-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
924 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,5 @@ __recovery/ | |
|
||
# Castalia statistics file (since XE7 Castalia is distributed with Delphi) | ||
*.stat | ||
|
||
/modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package HandleException; | ||
|
||
{$R *.res} | ||
{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users} | ||
{$ALIGN 8} | ||
{$ASSERTIONS ON} | ||
{$BOOLEVAL OFF} | ||
{$DEBUGINFO OFF} | ||
{$EXTENDEDSYNTAX ON} | ||
{$IMPORTEDDATA ON} | ||
{$IOCHECKS ON} | ||
{$LOCALSYMBOLS ON} | ||
{$LONGSTRINGS ON} | ||
{$OPENSTRINGS ON} | ||
{$OPTIMIZATION OFF} | ||
{$OVERFLOWCHECKS OFF} | ||
{$RANGECHECKS OFF} | ||
{$REFERENCEINFO ON} | ||
{$SAFEDIVIDE OFF} | ||
{$STACKFRAMES ON} | ||
{$TYPEDADDRESS OFF} | ||
{$VARSTRINGCHECKS ON} | ||
{$WRITEABLECONST OFF} | ||
{$MINENUMSIZE 1} | ||
{$IMAGEBASE $400000} | ||
{$DEFINE DEBUG} | ||
{$ENDIF IMPLICITBUILDING} | ||
{$RUNONLY} | ||
{$IMPLICITBUILD ON} | ||
|
||
requires | ||
rtl; | ||
|
||
contains | ||
Horse.HandleExcept in 'Src\Horse.HandleExcept.pas'; | ||
|
||
end. |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
# handle-exception | ||
# handle-exception | ||
Middleware for handle exception in HORSE | ||
|
||
Sample Horse Server | ||
```delphi | ||
uses | ||
Horse, Horse.HandleException; | ||
var | ||
App: THorse; | ||
begin | ||
App := THorse.Create(9000); | ||
App.Use(HandleException); | ||
App.Post('ping', | ||
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc) | ||
begin | ||
raise Exception.Create('My error!'); | ||
end); | ||
App.Start; | ||
end. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
unit Horse.HandleExcept; | ||
|
||
interface | ||
|
||
uses | ||
Horse, System.SysUtils; | ||
|
||
procedure HandleExcept(Req: THorseRequest; Res: THorseResponse; Next: TProc); | ||
|
||
implementation | ||
|
||
uses | ||
System.JSON; | ||
|
||
procedure HandleExcept(Req: THorseRequest; Res: THorseResponse; Next: TProc); | ||
var | ||
LJSON: TJSONObject; | ||
begin | ||
try | ||
Next(); | ||
except | ||
on E: Exception do | ||
begin | ||
LJSON := TJSONObject.Create; | ||
LJSON.AddPair('error', E.ClassName); | ||
LJSON.AddPair('description', E.Message); | ||
Res | ||
.Send<TJSONObject>(LJSON) | ||
.Status(400); | ||
end; | ||
end; | ||
end; | ||
|
||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"hash": "d41d8cd98f00b204e9800998ecf8427e", | ||
"updated": "2019-09-03T14:09:33.1801588-03:00", | ||
"installedModules": { | ||
"github.com/hashload/horse": { | ||
"name": "horse", | ||
"version": "1.6.8", | ||
"hash": "7a0b2394ac49dbd1a62f6d1021cac5b9", | ||
"artifacts": {}, | ||
"failed": false, | ||
"changed": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "handle-exception", | ||
"description": "", | ||
"version": "1.0.0", | ||
"homepage": "", | ||
"mainsrc": "Src/", | ||
"projects": [], | ||
"dependencies": { | ||
"github.com/hashload/horse": "^1.6.8" | ||
} | ||
} |