From bb5201ec920ec2d06541c5614ccd3a577608489a Mon Sep 17 00:00:00 2001 From: Matheus Hunsche Date: Tue, 3 Sep 2019 14:17:23 -0300 Subject: [PATCH] Initial commit --- .gitignore | 2 + HandleException.dpk | 37 ++ HandleException.dproj | 801 +++++++++++++++++++++++++++++++++++++ HandleException.res | Bin 0 -> 676 bytes README.md | 26 +- Src/Horse.HandleExcept.pas | 34 ++ boss-lock.json | 14 + boss.json | 11 + 8 files changed, 924 insertions(+), 1 deletion(-) create mode 100644 HandleException.dpk create mode 100644 HandleException.dproj create mode 100644 HandleException.res create mode 100644 Src/Horse.HandleExcept.pas create mode 100644 boss-lock.json create mode 100644 boss.json diff --git a/.gitignore b/.gitignore index 19864c6..94d28f9 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,5 @@ __recovery/ # Castalia statistics file (since XE7 Castalia is distributed with Delphi) *.stat + +/modules \ No newline at end of file diff --git a/HandleException.dpk b/HandleException.dpk new file mode 100644 index 0000000..cc72f9b --- /dev/null +++ b/HandleException.dpk @@ -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. diff --git a/HandleException.dproj b/HandleException.dproj new file mode 100644 index 0000000..3b7ce5a --- /dev/null +++ b/HandleException.dproj @@ -0,0 +1,801 @@ + + + {E0590034-6E1C-40BA-AAC5-BDB5AA6BC237} + HandleException.dpk + 18.7 + None + True + Debug + Win32 + 1 + Package + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + .\$(Platform)\$(Config) + .\$(Platform)\$(Config) + false + false + false + false + false + true + true + System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace) + All + true + HandleException + $(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\horse\src + + None + android-support-v4.dex.jar;cloud-messaging.dex.jar;com-google-android-gms.play-services-ads-base.17.2.0.dex.jar;com-google-android-gms.play-services-ads-identifier.16.0.0.dex.jar;com-google-android-gms.play-services-ads-lite.17.2.0.dex.jar;com-google-android-gms.play-services-ads.17.2.0.dex.jar;com-google-android-gms.play-services-analytics-impl.16.0.8.dex.jar;com-google-android-gms.play-services-analytics.16.0.8.dex.jar;com-google-android-gms.play-services-base.16.0.1.dex.jar;com-google-android-gms.play-services-basement.16.2.0.dex.jar;com-google-android-gms.play-services-gass.17.2.0.dex.jar;com-google-android-gms.play-services-identity.16.0.0.dex.jar;com-google-android-gms.play-services-maps.16.1.0.dex.jar;com-google-android-gms.play-services-measurement-base.16.4.0.dex.jar;com-google-android-gms.play-services-measurement-sdk-api.16.4.0.dex.jar;com-google-android-gms.play-services-stats.16.0.1.dex.jar;com-google-android-gms.play-services-tagmanager-v4-impl.16.0.8.dex.jar;com-google-android-gms.play-services-tasks.16.0.1.dex.jar;com-google-android-gms.play-services-wallet.16.0.1.dex.jar;com-google-firebase.firebase-analytics.16.4.0.dex.jar;com-google-firebase.firebase-common.16.1.0.dex.jar;com-google-firebase.firebase-iid-interop.16.0.1.dex.jar;com-google-firebase.firebase-iid.17.1.1.dex.jar;com-google-firebase.firebase-measurement-connector.17.0.1.dex.jar;com-google-firebase.firebase-messaging.17.5.0.dex.jar;fmx.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar + + + None + + + None + + + None + + + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + Debug + true + CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= + 1033 + + + DEBUG;$(DCC_Define) + true + false + true + true + true + + + false + true + 1033 + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + + MainSource + + + + + Cfg_2 + Base + + + Base + + + Cfg_1 + Base + + + + Delphi.Personality.12 + Package + + + + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + + + HandleException.dpk + + + + + + true + + + + + true + + + + + true + + + + + HandleException.bpl + true + + + + + 1 + + + 0 + + + + + classes + 1 + + + + + res\xml + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\armeabi + 1 + + + + + library\lib\mips + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + res\drawable + 1 + + + + + res\values + 1 + + + + + res\values-v21 + 1 + + + + + res\values + 1 + + + + + res\drawable + 1 + + + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-ldpi + 1 + + + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-xxxhdpi + 1 + + + + + res\drawable-small + 1 + + + + + res\drawable-normal + 1 + + + + + res\drawable-large + 1 + + + + + res\drawable-xlarge + 1 + + + + + res\values + 1 + + + + + 1 + + + 1 + + + 0 + + + + + 1 + .framework + + + 1 + .framework + + + 0 + + + + + 1 + .dylib + + + 1 + .dylib + + + 0 + .dll;.bpl + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + 0 + .bpl + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + 1 + + + 1 + + + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + + + + 1 + + + 1 + + + 1 + + + + + + + + Contents\Resources + 1 + + + Contents\Resources + 1 + + + + + library\lib\armeabi-v7a + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + 0 + + + + + 1 + + + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + + + + + + + + + + False + False + False + False + False + True + False + + + 12 + + + + + diff --git a/HandleException.res b/HandleException.res new file mode 100644 index 0000000000000000000000000000000000000000..091a03e538711b5f7b90c57c6ef5a827aa825d56 GIT binary patch literal 676 zcma))%}T>i5QR@m7S>fCp^K~~LN@vtOr%(mj*yrfTt)-6 z@%8u~J};UX&og`rd@~C(&=hTMtbM(KNmWNg+N<$Quof_F{10_NR4>x4I^b_W<>Xty zz9QS6#hUT90-JI_U@3?;CAQ&@sp6eCwH63;l(tp(wTP@rEyA|!$<1%kB zS(mNv=BE2nXp>8<(u~e5LDu`*3O)l?NXJN7?$enIb(Pp&jC6_CWoOQrTEe8OQ{OMQ F6F;>AULODe literal 0 HcmV?d00001 diff --git a/README.md b/README.md index 4e8b588..963225d 100644 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ -# handle-exception \ No newline at end of file +# 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. +``` diff --git a/Src/Horse.HandleExcept.pas b/Src/Horse.HandleExcept.pas new file mode 100644 index 0000000..ddbc962 --- /dev/null +++ b/Src/Horse.HandleExcept.pas @@ -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(LJSON) + .Status(400); + end; + end; +end; + +end. diff --git a/boss-lock.json b/boss-lock.json new file mode 100644 index 0000000..8741cb1 --- /dev/null +++ b/boss-lock.json @@ -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 + } + } +} \ No newline at end of file diff --git a/boss.json b/boss.json new file mode 100644 index 0000000..1cd2606 --- /dev/null +++ b/boss.json @@ -0,0 +1,11 @@ +{ + "name": "handle-exception", + "description": "", + "version": "1.0.0", + "homepage": "", + "mainsrc": "Src/", + "projects": [], + "dependencies": { + "github.com/hashload/horse": "^1.6.8" + } +} \ No newline at end of file