feat: Expose API Response on Api Error
This commit is contained in:
parent
491ab2d0ee
commit
de08e5e4ee
1 changed files with 10 additions and 2 deletions
|
|
@ -133,7 +133,7 @@ namespace QuickChart
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
throw new Exception("Unsuccessful response from API");
|
throw new ApiException("Unsuccessful response from API", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
string responseText = response.Content.ReadAsStringAsync().Result;
|
string responseText = response.Content.ReadAsStringAsync().Result;
|
||||||
|
|
@ -172,7 +172,7 @@ namespace QuickChart
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
throw new Exception("Unsuccessful response from API");
|
throw new ApiException("Unsuccessful response from API", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.Content.ReadAsByteArrayAsync().Result;
|
return response.Content.ReadAsByteArrayAsync().Result;
|
||||||
|
|
@ -183,4 +183,12 @@ namespace QuickChart
|
||||||
File.WriteAllBytes(filePath, this.ToByteArray());
|
File.WriteAllBytes(filePath, this.ToByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ApiException : Exception
|
||||||
|
{
|
||||||
|
public ApiException(string message, HttpResponseMessage response) : base(message)
|
||||||
|
=> this.Response = response;
|
||||||
|
|
||||||
|
public HttpResponseMessage Response { get; private set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue