From de08e5e4ee8becb1508a4e8b08a894c776a53f2d Mon Sep 17 00:00:00 2001 From: Mira <56395159+TheXorog@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:52:24 +0200 Subject: [PATCH] feat: Expose API Response on Api Error --- QuickChart/QuickChart.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/QuickChart/QuickChart.cs b/QuickChart/QuickChart.cs index 93ba667..01d16e6 100644 --- a/QuickChart/QuickChart.cs +++ b/QuickChart/QuickChart.cs @@ -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; } + } }