Skip to content

Commit 3b70b76

Browse files
Merge pull request #12 from gabrielbaltazar/master
maintain error status, on exception, when previously informed.
2 parents 3a0168e + cdd1c4d commit 3b70b76

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Src/Horse.HandleException.pas

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ procedure SendError(ARes:THorseResponse; AJson: TJSONObject; AStatus: Integer);
3333
procedure HandleException(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED(FPC)}TNextProc{$ELSE}TProc{$ENDIF});
3434
var
3535
LJSON: TJSONObject;
36+
LStatus: Integer;
3637
begin
3738
try
3839
Next();
@@ -63,9 +64,12 @@ procedure HandleException(Req: THorseRequest; Res: THorseResponse; Next: {$IF DE
6364
end;
6465
on E: Exception do
6566
begin
67+
LStatus := Res.Status;
68+
if LStatus < Integer(THTTPStatus.BadRequest) then
69+
LStatus := Integer(THTTPStatus.InternalServerError);
6670
LJSON := TJSONObject.Create;
6771
LJSON.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}('error', E.Message);
68-
SendError(Res, LJSON, Integer(THTTPStatus.InternalServerError));
72+
SendError(Res, LJSON, LStatus);
6973
end;
7074
end;
7175
end;

0 commit comments

Comments
 (0)