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); } } }