Skip to content

Commit bb5201e

Browse files
committed
Initial commit
1 parent cfed428 commit bb5201e

File tree

8 files changed

+924
-1
lines changed

8 files changed

+924
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ __recovery/
6464

6565
# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
6666
*.stat
67+
68+
/modules

HandleException.dpk

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package HandleException;
2+
3+
{$R *.res}
4+
{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}
5+
{$ALIGN 8}
6+
{$ASSERTIONS ON}
7+
{$BOOLEVAL OFF}
8+
{$DEBUGINFO OFF}
9+
{$EXTENDEDSYNTAX ON}
10+
{$IMPORTEDDATA ON}
11+
{$IOCHECKS ON}
12+
{$LOCALSYMBOLS ON}
13+
{$LONGSTRINGS ON}
14+
{$OPENSTRINGS ON}
15+
{$OPTIMIZATION OFF}
16+
{$OVERFLOWCHECKS OFF}
17+
{$RANGECHECKS OFF}
18+
{$REFERENCEINFO ON}
19+
{$SAFEDIVIDE OFF}
20+
{$STACKFRAMES ON}
21+
{$TYPEDADDRESS OFF}
22+
{$VARSTRINGCHECKS ON}
23+
{$WRITEABLECONST OFF}
24+
{$MINENUMSIZE 1}
25+
{$IMAGEBASE $400000}
26+
{$DEFINE DEBUG}
27+
{$ENDIF IMPLICITBUILDING}
28+
{$RUNONLY}
29+
{$IMPLICITBUILD ON}
30+
31+
requires
32+
rtl;
33+
34+
contains
35+
Horse.HandleExcept in 'Src\Horse.HandleExcept.pas';
36+
37+
end.

HandleException.dproj

Lines changed: 801 additions & 0 deletions
Large diffs are not rendered by default.

HandleException.res

676 Bytes
Binary file not shown.

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
1-
# handle-exception
1+
# handle-exception
2+
Middleware for handle exception in HORSE
3+
4+
Sample Horse Server
5+
```delphi
6+
uses
7+
Horse, Horse.HandleException;
8+
9+
var
10+
App: THorse;
11+
12+
begin
13+
App := THorse.Create(9000);
14+
15+
App.Use(HandleException);
16+
17+
App.Post('ping',
18+
procedure(Req: THorseRequest; Res: THorseResponse; Next: TProc)
19+
begin
20+
raise Exception.Create('My error!');
21+
end);
22+
23+
App.Start;
24+
end.
25+
```

Src/Horse.HandleExcept.pas

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
unit Horse.HandleExcept;
2+
3+
interface
4+
5+
uses
6+
Horse, System.SysUtils;
7+
8+
procedure HandleExcept(Req: THorseRequest; Res: THorseResponse; Next: TProc);
9+
10+
implementation
11+
12+
uses
13+
System.JSON;
14+
15+
procedure HandleExcept(Req: THorseRequest; Res: THorseResponse; Next: TProc);
16+
var
17+
LJSON: TJSONObject;
18+
begin
19+
try
20+
Next();
21+
except
22+
on E: Exception do
23+
begin
24+
LJSON := TJSONObject.Create;
25+
LJSON.AddPair('error', E.ClassName);
26+
LJSON.AddPair('description', E.Message);
27+
Res
28+
.Send<TJSONObject>(LJSON)
29+
.Status(400);
30+
end;
31+
end;
32+
end;
33+
34+
end.

boss-lock.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"hash": "d41d8cd98f00b204e9800998ecf8427e",
3+
"updated": "2019-09-03T14:09:33.1801588-03:00",
4+
"installedModules": {
5+
"github.com/hashload/horse": {
6+
"name": "horse",
7+
"version": "1.6.8",
8+
"hash": "7a0b2394ac49dbd1a62f6d1021cac5b9",
9+
"artifacts": {},
10+
"failed": false,
11+
"changed": false
12+
}
13+
}
14+
}

boss.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "handle-exception",
3+
"description": "",
4+
"version": "1.0.0",
5+
"homepage": "",
6+
"mainsrc": "Src/",
7+
"projects": [],
8+
"dependencies": {
9+
"github.com/hashload/horse": "^1.6.8"
10+
}
11+
}

0 commit comments

Comments
 (0)