feat: Expose API Response on Api Error

This commit is contained in:
Mira 2023-09-21 16:52:24 +02:00
parent 491ab2d0ee
commit de08e5e4ee
Signed by untrusted user who does not match committer: Xorog
GPG key ID: 983798ED9C3E7C36

View file

@ -133,7 +133,7 @@ namespace QuickChart
if (!response.IsSuccessStatusCode)
{
throw new Exception("Unsuccessful response from API");
throw new ApiException("Unsuccessful response from API", response);
}
string responseText = response.Content.ReadAsStringAsync().Result;
@ -172,7 +172,7 @@ namespace QuickChart
if (!response.IsSuccessStatusCode)
{
throw new Exception("Unsuccessful response from API");
throw new ApiException("Unsuccessful response from API", response);
}
return response.Content.ReadAsByteArrayAsync().Result;
@ -183,4 +183,12 @@ namespace QuickChart
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; }
}
}