Skip to content

Commit

Permalink
Fixed error message formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
svekl committed Apr 11, 2016
1 parent 50873bb commit 5b0d561
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 262 deletions.
4 changes: 2 additions & 2 deletions SquareConnectApiClient.Client/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
<Import Project="$(NuProjPath)\NuProj.props" Condition="Exists('$(NuProjPath)\NuProj.props')" />
<PropertyGroup Label="Configuration">
<Id>SquareConnectApiClient</Id>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<Title>Square Connect API Client</Title>
<Authors>Sergei Svekolnikov</Authors>
<Owners>Sergei Svekolnikov</Owners>
<Summary>Client for Square Connect API</Summary>
<Description>Client for Square Connect API. Generated with https://generator.swagger.io</Description>
<ReleaseNotes>Target framework changed to 4.5</ReleaseNotes>
<ReleaseNotes>Fixed error message formatting</ReleaseNotes>
<ProjectUrl>https://github.com/svekl/square-connect-api-client</ProjectUrl>
<LicenseUrl>
</LicenseUrl>
Expand Down
4 changes: 2 additions & 2 deletions SquareConnectApiClient.V1/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
63 changes: 63 additions & 0 deletions SquareConnectApiClient.V2/Api/ApiV2Exception.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using RestSharp;
using SquareConnectApiClient.Client;
using SquareConnectApiClient.V2.Model;

namespace SquareConnectApiClient.V2.Api
{
public class ApiV2Exception : ApiException
{
private static string GetErrorMessage(string errorContent, string errorMessage)
{
try
{
var errorsArray = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorsArray>(errorContent);
return FlattenErrorsArray(errorsArray.Errors);
}
catch (Exception)
{
return errorMessage;
}
}

private static string FlattenErrorsArray(Error[] errors)
{
return string.Join("; ", errors.Select(x =>
{
var resultText = new StringBuilder();
if (x.Category != null)
{
resultText.Append(x.Category.ToString());
resultText.Append(" - ");
}
if (x.Code != null) resultText.Append(x.Code.ToString());
if (!string.IsNullOrWhiteSpace(x.Field))
{
resultText.Append(" at field \"");
resultText.Append(x.Field);
resultText.Append("\"");
}
resultText.Append(" : ");
resultText.Append(x.Detail);
return resultText.ToString();
}));
}

public ApiV2Exception(int errorCode, string message) : base(errorCode, message)
{

}

public ApiV2Exception(int errorCode, string message, string errorContent) : base(errorCode, GetErrorMessage(errorContent, message), errorContent)
{
this.ErrorCode = errorCode;
}
}
}
160 changes: 80 additions & 80 deletions SquareConnectApiClient.V2/Api/CustomerApi.cs

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions SquareConnectApiClient.V2/Api/CustomerCardApi.cs

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions SquareConnectApiClient.V2/Api/LocationApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface ILocationApi
/// <remarks>
/// Provides summary information for all of a business&#39;s locations.
/// </remarks>
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception>
/// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param>
/// <returns>ListLocationsResponse</returns>
ListLocationsResponse ListLocations (string authorization);
Expand All @@ -32,7 +32,7 @@ public interface ILocationApi
/// <remarks>
/// Provides summary information for all of a business&#39;s locations.
/// </remarks>
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception>
/// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param>
/// <returns>ApiResponse of ListLocationsResponse</returns>
ApiResponse<ListLocationsResponse> ListLocationsWithHttpInfo (string authorization);
Expand All @@ -47,7 +47,7 @@ public interface ILocationApi
/// <remarks>
/// Provides summary information for all of a business&#39;s locations.
/// </remarks>
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception>
/// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param>
/// <returns>Task of ListLocationsResponse</returns>
System.Threading.Tasks.Task<ListLocationsResponse> ListLocationsAsync (string authorization);
Expand All @@ -58,7 +58,7 @@ public interface ILocationApi
/// <remarks>
/// Provides summary information for all of a business&#39;s locations.
/// </remarks>
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception>
/// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param>
/// <returns>Task of ApiResponse (ListLocationsResponse)</returns>
System.Threading.Tasks.Task<ApiResponse<ListLocationsResponse>> ListLocationsAsyncWithHttpInfo (string authorization);
Expand Down Expand Up @@ -158,7 +158,7 @@ public void AddDefaultHeader(string key, string value)
/// <summary>
/// ListLocations Provides summary information for all of a business&#39;s locations.
/// </summary>
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception>
/// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param>
/// <returns>ListLocationsResponse</returns>
public ListLocationsResponse ListLocations (string authorization)
Expand All @@ -170,15 +170,15 @@ public ListLocationsResponse ListLocations (string authorization)
/// <summary>
/// ListLocations Provides summary information for all of a business&#39;s locations.
/// </summary>
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception>
/// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param>
/// <returns>ApiResponse of ListLocationsResponse</returns>
public ApiResponse< ListLocationsResponse > ListLocationsWithHttpInfo (string authorization)
{

// verify the required parameter 'authorization' is set
if (authorization == null)
throw new ApiException(400, "Missing required parameter 'authorization' when calling LocationApi->ListLocations");
throw new ApiV2Exception(400, "Missing required parameter 'authorization' when calling LocationApi->ListLocations");


var localVarPath = "/v2/locations";
Expand Down Expand Up @@ -224,9 +224,9 @@ public ApiResponse< ListLocationsResponse > ListLocationsWithHttpInfo (string au
int localVarStatusCode = (int) localVarResponse.StatusCode;

if (localVarStatusCode >= 400)
throw new ApiException (localVarStatusCode, "Error calling ListLocations: " + localVarResponse.Content, localVarResponse.Content);
throw new ApiV2Exception (localVarStatusCode, "Error calling ListLocations: " + localVarResponse.Content, localVarResponse.Content);
else if (localVarStatusCode == 0)
throw new ApiException (localVarStatusCode, "Error calling ListLocations: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);
throw new ApiV2Exception (localVarStatusCode, "Error calling ListLocations: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);

return new ApiResponse<ListLocationsResponse>(localVarStatusCode,
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
Expand All @@ -238,7 +238,7 @@ public ApiResponse< ListLocationsResponse > ListLocationsWithHttpInfo (string au
/// <summary>
/// ListLocations Provides summary information for all of a business&#39;s locations.
/// </summary>
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception>
/// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param>
/// <returns>Task of ListLocationsResponse</returns>
public async System.Threading.Tasks.Task<ListLocationsResponse> ListLocationsAsync (string authorization)
Expand All @@ -251,13 +251,13 @@ public async System.Threading.Tasks.Task<ListLocationsResponse> ListLocationsAsy
/// <summary>
/// ListLocations Provides summary information for all of a business&#39;s locations.
/// </summary>
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
/// <exception cref="ApiV2Exception">Thrown when fails to make API call</exception>
/// <param name="authorization">The value to provide in the Authorization header of\nyour request. This value should follow the format `Bearer YOUR_ACCESS_TOKEN_HERE`.</param>
/// <returns>Task of ApiResponse (ListLocationsResponse)</returns>
public async System.Threading.Tasks.Task<ApiResponse<ListLocationsResponse>> ListLocationsAsyncWithHttpInfo (string authorization)
{
// verify the required parameter 'authorization' is set
if (authorization == null) throw new ApiException(400, "Missing required parameter 'authorization' when calling ListLocations");
if (authorization == null) throw new ApiV2Exception(400, "Missing required parameter 'authorization' when calling ListLocations");


var localVarPath = "/v2/locations";
Expand Down Expand Up @@ -303,9 +303,9 @@ public async System.Threading.Tasks.Task<ApiResponse<ListLocationsResponse>> Lis
int localVarStatusCode = (int) localVarResponse.StatusCode;

if (localVarStatusCode >= 400)
throw new ApiException (localVarStatusCode, "Error calling ListLocations: " + localVarResponse.Content, localVarResponse.Content);
throw new ApiV2Exception (localVarStatusCode, "Error calling ListLocations: " + localVarResponse.Content, localVarResponse.Content);
else if (localVarStatusCode == 0)
throw new ApiException (localVarStatusCode, "Error calling ListLocations: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);
throw new ApiV2Exception (localVarStatusCode, "Error calling ListLocations: " + localVarResponse.ErrorMessage, localVarResponse.ErrorMessage);

return new ApiResponse<ListLocationsResponse>(localVarStatusCode,
localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
Expand Down
Loading

0 comments on commit 5b0d561

Please sign in to comment.