From cdd1c4dc1bf60c22644d19de463633b626a6c1b7 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 8 Jan 2022 13:39:01 -0300 Subject: [PATCH] maintain error status, on exception, when previously informed. --- Src/Horse.HandleException.pas | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Src/Horse.HandleException.pas b/Src/Horse.HandleException.pas index b4c26f6..00fe4ee 100644 --- a/Src/Horse.HandleException.pas +++ b/Src/Horse.HandleException.pas @@ -33,6 +33,7 @@ procedure SendError(ARes:THorseResponse; AJson: TJSONObject; AStatus: Integer); procedure HandleException(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED(FPC)}TNextProc{$ELSE}TProc{$ENDIF}); var LJSON: TJSONObject; + LStatus: Integer; begin try Next(); @@ -63,9 +64,12 @@ procedure HandleException(Req: THorseRequest; Res: THorseResponse; Next: {$IF DE end; on E: Exception do begin + LStatus := Res.Status; + if LStatus < Integer(THTTPStatus.BadRequest) then + LStatus := Integer(THTTPStatus.InternalServerError); LJSON := TJSONObject.Create; LJSON.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}('error', E.Message); - SendError(Res, LJSON, Integer(THTTPStatus.InternalServerError)); + SendError(Res, LJSON, LStatus); end; end; end;