@@ -230,7 +230,9 @@ namespace {{ spec.title | caseUcfirst }}
230230 var code = (int)response.StatusCode;
231231
232232 if (code >= 400) {
233- var message = await response.Content.ReadAsStringAsync();
233+ var text = await response.Content.ReadAsStringAsync();
234+ var message = "";
235+ var type = "";
234236
235237 string contentType = string.Empty;
236238 if (response.Content.Headers.TryGetValues("Content-Type", out var contentTypes))
@@ -239,10 +241,13 @@ namespace {{ spec.title | caseUcfirst }}
239241 }
240242
241243 if (contentType.Contains("application/json")) {
242- message = JObject.Parse(message)["message"]!.ToString();
244+ message = JObject.Parse(text)["message"]!.ToString();
245+ type = JObject.Parse(text)["type"]?.ToString() ?? string.Empty;
246+ } else {
247+ message = text;
243248 }
244249
245- throw new {{spec .title | caseUcfirst }}Exception(message, code);
250+ throw new {{spec .title | caseUcfirst }}Exception(message, code, type, text );
246251 }
247252
248253 return response.Headers.Location.OriginalString;
@@ -286,13 +291,18 @@ namespace {{ spec.title | caseUcfirst }}
286291 var isJson = contentType.Contains("application/json");
287292
288293 if (code >= 400) {
289- var message = await response.Content.ReadAsStringAsync();
294+ var text = await response.Content.ReadAsStringAsync();
295+ var message = "";
296+ var type = "";
290297
291298 if (isJson) {
292- message = JObject.Parse(message)["message"]!.ToString();
299+ message = JObject.Parse(text)["message"]!.ToString();
300+ type = JObject.Parse(text)["type"]?.ToString() ?? string.Empty;
301+ } else {
302+ message = text;
293303 }
294304
295- throw new {{spec .title | caseUcfirst }}Exception(message, code);
305+ throw new {{spec .title | caseUcfirst }}Exception(message, code, type, text );
296306 }
297307
298308 if (isJson)
0 commit comments