documentation
This commit is contained in:
@ -1,15 +1,36 @@
|
||||
#pragma warning disable 1591
|
||||
|
||||
|
||||
using System;
|
||||
using NAMESPACEPLACEHOLDER.Model;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
||||
namespace NAMESPACEPLACEHOLDER.Client {
|
||||
/// <summary>
|
||||
/// Extended API Exception, provides ErrorCode (http code), ServiceErrorCode (service
|
||||
/// specific error code), status message (via super class ApiException), help link
|
||||
/// (also via super class ApiException) and offensive data via properties of the exception
|
||||
/// itself.
|
||||
/// Usually when openapi specificiation provided ErrorResultObject type for endpoints
|
||||
/// which returns an object of that type in case of errors greater or equal then 400,
|
||||
/// in particular for 400 and 500.
|
||||
/// To use this Extended API Exception set the ExceptionFactory immediately after
|
||||
/// instantiating the API object to ExtApiException.ExtExceptionFactory.
|
||||
/// </summary>
|
||||
public class ExtApiException: ApiException {
|
||||
/// <summary>
|
||||
/// ErrorCode, this is the http code returned by the webservice
|
||||
/// readonly property
|
||||
/// </summary>
|
||||
public int ErrorCode { get; }
|
||||
/// <summary>
|
||||
/// ServiceErrorCode, this is the service specific error code, compare to the
|
||||
/// serviceErrorCodes.yaml in the webservice project
|
||||
/// readonly property
|
||||
/// </summary>
|
||||
public int ServiceErrorCode { get; }
|
||||
/// <summary>
|
||||
/// OffensiveData, repeats the data sent to the webservice which led to this
|
||||
/// particular error
|
||||
/// readonly property
|
||||
/// </summary>
|
||||
public String OffensiveData { get; }
|
||||
|
||||
public ExtApiException(ErrorResultObject ero): base(ero.errorCode, ero.errorMessage, ero) {
|
||||
@ -18,6 +39,11 @@ namespace NAMESPACEPLACEHOLDER.Client {
|
||||
OffensiveData = ero.offensiveData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ExceptionFactory to transform the http response of errors from the webservice into the
|
||||
/// ExtApiException
|
||||
/// Set it immediately after instantiating the API object within the new object.
|
||||
/// </summary>
|
||||
public static ExceptionFactory ExtExceptionFactory = (methodName, response) => {
|
||||
return (((int)response.StatusCode) >= 400) ? new ExtApiException(JsonConvert.DeserializeObject<ErrorResultObject>(response.RawContent)) : null;
|
||||
};
|
||||
@ -25,4 +51,3 @@ namespace NAMESPACEPLACEHOLDER.Client {
|
||||
}
|
||||
|
||||
|
||||
#pragma warning restore 1591
|
||||
|
Reference in New Issue
Block a user