-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
343 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.