Extended the APIException by ErrorContent from response body

This commit is contained in:
Fredrik Gustafsson 2015-06-03 16:23:45 +02:00
parent 41e4fc79ae
commit 217765998d
2 changed files with 9 additions and 2 deletions

View File

@ -83,7 +83,7 @@ namespace {{package}} {
// make the HTTP request
IRestResponse response = restClient.Execute(_request);
if (((int)response.StatusCode) >= 400) {
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content);
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
}
{{#returnType}}return ({{{returnType}}}) ApiInvoker.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
return;{{/returnType}}
@ -125,7 +125,7 @@ namespace {{package}} {
// make the HTTP request
IRestResponse response = await restClient.ExecuteTaskAsync(_request);
if (((int)response.StatusCode) >= 400) {
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content);
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
}
{{#returnType}}return ({{{returnType}}}) ApiInvoker.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
return;{{/returnType}}

View File

@ -6,12 +6,19 @@ namespace {{invokerPackage}} {
public int ErrorCode { get; set; }
public dynamic ErrorContent { get; private set; }
public ApiException() {}
public ApiException(int errorCode, string message) : base(message) {
this.ErrorCode = errorCode;
}
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message) {
this.errorCode = errorCode;
this.errorContent = errorContent;
}
}
}