From 02f90577b0a78e867803d1b8273f7e077a097c36 Mon Sep 17 00:00:00 2001 From: viniciussanchez Date: Tue, 12 May 2020 22:55:48 -0300 Subject: [PATCH] EHorseException handler --- HandleException.dproj | 149 +++++++++++++++++++++++++++++++++- Src/Horse.HandleException.pas | 19 +++-- boss-lock.json | 8 +- 3 files changed, 161 insertions(+), 15 deletions(-) diff --git a/HandleException.dproj b/HandleException.dproj index fd50397..bc7b498 100644 --- a/HandleException.dproj +++ b/HandleException.dproj @@ -2,7 +2,7 @@ {E0590034-6E1C-40BA-AAC5-BDB5AA6BC237} HandleException.dpk - 18.7 + 18.8 None True Debug @@ -18,6 +18,11 @@ Base true + + true + Base + true + true Base @@ -53,12 +58,21 @@ All true HandleException - $(DCC_UnitSearchPath);modules\.dcp;modules\.dcu;modules;modules\horse\src;modules\jhonson\src + modules\.dcp;modules\.dcu;modules;modules\horse\src;modules\jhonson\src;$(DCC_UnitSearchPath) 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 + + package=com.embarcadero.$(MSBuildProjectName);label=$(MSBuildProjectName);versionCode=1;versionName=1.0.0;persistent=False;restoreAnyVersion=False;installLocation=auto;largeHeap=False;theme=TitleBar;hardwareAccelerated=true;apiKey= + Debug + true + Base + true + 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 + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) Debug @@ -151,12 +165,20 @@ classes 1 + + classes + 1 + res\xml 1 + + res\xml + 1 + @@ -169,138 +191,242 @@ library\lib\armeabi 1 + + library\lib\armeabi + 1 + + + + + library\lib\armeabi-v7a + 1 + library\lib\mips 1 + + library\lib\mips + 1 + library\lib\armeabi-v7a 1 + + library\lib\arm64-v8a + 1 + + + + + library\lib\armeabi-v7a + 1 + res\drawable 1 + + res\drawable + 1 + res\values 1 + + res\values + 1 + res\values-v21 1 + + res\values-v21 + 1 + res\values 1 + + res\values + 1 + res\drawable 1 + + res\drawable + 1 + res\drawable-xxhdpi 1 + + res\drawable-xxhdpi + 1 + res\drawable-ldpi 1 + + res\drawable-ldpi + 1 + res\drawable-mdpi 1 + + res\drawable-mdpi + 1 + res\drawable-hdpi 1 + + res\drawable-hdpi + 1 + res\drawable-xhdpi 1 + + res\drawable-xhdpi + 1 + res\drawable-mdpi 1 + + res\drawable-mdpi + 1 + res\drawable-hdpi 1 + + res\drawable-hdpi + 1 + res\drawable-xhdpi 1 + + res\drawable-xhdpi + 1 + res\drawable-xxhdpi 1 + + res\drawable-xxhdpi + 1 + res\drawable-xxxhdpi 1 + + res\drawable-xxxhdpi + 1 + res\drawable-small 1 + + res\drawable-small + 1 + res\drawable-normal 1 + + res\drawable-normal + 1 + res\drawable-large 1 + + res\drawable-large + 1 + res\drawable-xlarge 1 + + res\drawable-xlarge + 1 + res\values 1 + + res\values + 1 + @@ -370,6 +496,9 @@ 0 + + 0 + 0 @@ -657,6 +786,9 @@ 1 + + 1 + @@ -700,6 +832,10 @@ library\lib\armeabi-v7a 1 + + library\lib\arm64-v8a + 1 + 1 @@ -722,6 +858,12 @@ 0 + + + library\lib\armeabi-v7a + 1 + + 1 @@ -759,10 +901,11 @@ + False - False + False True False diff --git a/Src/Horse.HandleException.pas b/Src/Horse.HandleException.pas index c6fd682..9ad157d 100644 --- a/Src/Horse.HandleException.pas +++ b/Src/Horse.HandleException.pas @@ -2,15 +2,13 @@ interface -uses - Horse, System.SysUtils; +uses Horse, Horse.Commons, System.SysUtils; procedure HandleException(Req: THorseRequest; Res: THorseResponse; Next: TProc); implementation -uses - System.JSON; +uses System.JSON; procedure HandleException(Req: THorseRequest; Res: THorseResponse; Next: TProc); var @@ -21,15 +19,20 @@ procedure HandleException(Req: THorseRequest; Res: THorseResponse; Next: TProc); except on E: EHorseCallbackInterrupted do raise; - + + on E: EHorseException do + begin + LJSON := TJSONObject.Create; + LJSON.AddPair('error', E.Error); + Res.Send(LJSON).Status(E.Status); + end; + on E: Exception do begin LJSON := TJSONObject.Create; LJSON.AddPair('error', E.ClassName); LJSON.AddPair('description', E.Message); - Res - .Send(LJSON) - .Status(400); + Res.Send(LJSON).Status(THTTPStatus.BadRequest); end; end; end; diff --git a/boss-lock.json b/boss-lock.json index 0fed573..0cb3bbd 100644 --- a/boss-lock.json +++ b/boss-lock.json @@ -4,16 +4,16 @@ "installedModules": { "github.com/hashload/horse": { "name": "horse", - "version": "1.6.8", - "hash": "7a0b2394ac49dbd1a62f6d1021cac5b9", + "version": "1.7.3", + "hash": "66c1cafebc6ec755c77b01d51d6c76d6", "artifacts": {}, "failed": false, "changed": false }, "github.com/hashload/jhonson": { "name": "jhonson", - "version": "1.0.3", - "hash": "334dfe6b2e7daa4cb6af5b1bf88ec76e", + "version": "1.0.4", + "hash": "545935215f295163e4c3927bd21edea2", "artifacts": {}, "failed": false, "changed": false