Skip to content

Commit

Permalink
Merge pull request #12 from gabrielbaltazar/master
Browse files Browse the repository at this point in the history
maintain error status, on exception, when previously informed.
  • Loading branch information
viniciussanchez authored Jan 12, 2022
2 parents 3a0168e + cdd1c4d commit 3b70b76
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Src/Horse.HandleException.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3b70b76

Please sign in to comment.