Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hunsche committed Sep 3, 2019
1 parent cfed428 commit bb5201e
Show file tree
Hide file tree
Showing 8 changed files with 924 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ __recovery/

# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
*.stat

/modules
37 changes: 37 additions & 0 deletions HandleException.dpk
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.
801 changes: 801 additions & 0 deletions HandleException.dproj

Large diffs are not rendered by default.

Binary file added HandleException.res
Binary file not shown.
26 changes: 25 additions & 1 deletion README.md
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.
```
34 changes: 34 additions & 0 deletions Src/Horse.HandleExcept.pas
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.
14 changes: 14 additions & 0 deletions boss-lock.json
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
}
}
}
11 changes: 11 additions & 0 deletions boss.json
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"
}
}

0 comments on commit bb5201e

Please sign in to comment.