File tree Expand file tree Collapse file tree 8 files changed +924
-1
lines changed Expand file tree Collapse file tree 8 files changed +924
-1
lines changed Original file line number Diff line number Diff line change @@ -64,3 +64,5 @@ __recovery/
64
64
65
65
# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
66
66
* .stat
67
+
68
+ /modules
Original file line number Diff line number Diff line change
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.
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 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
+ ```
Original file line number Diff line number Diff line change
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 .
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments