add the extended exception

This commit is contained in:
2021-12-08 16:10:00 +01:00
parent 1db317df59
commit c2cbc96d83
2 changed files with 34 additions and 3 deletions

33
ClientExtApiException.cs Normal file
View File

@ -0,0 +1,33 @@
#pragma warning disable 1591
using System;
using NAMESPACEPLACEHOLDER.Model;
using Newtonsoft.Json;
namespace NAMESPACEPLACEHOLDER.Client {
class ExtApiException: ApiException {
public int ErrorCode { get; }
public int ServiceErrorCode { get; }
public String OffensiveData { get; }
public ExtApiException(ErrorResultObject ero): base(ero.errorCode, ero.errorMessage, ero) {
ErrorCode = ero.errorCode;
ServiceErrorCode = ero.serviceErrorCode;
OffensiveData = ero.offensiveData;
}
public static ExceptionFactory ExtExceptionFactory = (methodName, response) => {
var status = (int) response.StatusCode;
if (status >= 400) {
var ero = JsonConvert.DeserializeObject<ErrorResultObject>(response.RawContent);
return new ExtApiException(ero);
}
return null;
};
}
}
#pragma warning restore 1591