From 82393eb8bbcaa10865b21e890c01f41eeb389660 Mon Sep 17 00:00:00 2001 From: rockstardev Date: Mon, 3 Feb 2020 02:18:36 -0600 Subject: [PATCH] Fixing api exception handling in the pipeline --- BTCPayServer/Hosting/BTCpayMiddleware.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/BTCPayServer/Hosting/BTCpayMiddleware.cs b/BTCPayServer/Hosting/BTCpayMiddleware.cs index d58c2953d..7175fd0d4 100644 --- a/BTCPayServer/Hosting/BTCpayMiddleware.cs +++ b/BTCPayServer/Hosting/BTCpayMiddleware.cs @@ -62,10 +62,12 @@ namespace BTCPayServer.Hosting catch (UnauthorizedAccessException ex) { await HandleBitpayHttpException(httpContext, new BitpayHttpException(401, ex.Message)); + return; } catch (BitpayHttpException ex) { await HandleBitpayHttpException(httpContext, ex); + return; } catch (Exception ex) { @@ -133,13 +135,9 @@ namespace BTCPayServer.Hosting private static async Task HandleBitpayHttpException(HttpContext httpContext, BitpayHttpException ex) { httpContext.Response.StatusCode = ex.StatusCode; - using (var writer = new StreamWriter(httpContext.Response.Body, new UTF8Encoding(false), 1024, true)) - { - httpContext.Response.ContentType = "application/json"; - var result = JsonConvert.SerializeObject(new BitpayErrorsModel(ex)); - writer.Write(result); - await writer.FlushAsync(); - } + httpContext.Response.ContentType = "application/json"; + var result = JsonConvert.SerializeObject(new BitpayErrorsModel(ex)); + await httpContext.Response.WriteAsync(result); } } }