Skip to content

Commit 2a5a4cf

Browse files
committed
add(feat): integration of validation error in the standard error processing
1 parent 1d9df75 commit 2a5a4cf

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

samples/validation_showcase/ValidationShowcaseClient.dpr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ begin
358358
try
359359
LBody.S['name'] := 'Mario Rossi';
360360
LBody.S['email'] := 'mario.rossi@example.it';
361-
LBody.S['taxId'] := 'RSSMRA85M01H501Z';
361+
LBody.S['taxId'] := 'RSSMRA85M01H501Q';
362362
LBody.O['billingAddress'].S['street'] := 'Via Roma 123';
363363
LBody.O['billingAddress'].S['city'] := 'Roma';
364364
LBody.O['billingAddress'].S['postalCode'] := '00100';

sources/MVCFramework.Serializer.JsonDataObjects.CustomTypes.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ interface
3838
MVCFramework.Serializer.Intf,
3939
MVCFramework.Serializer.Commons,
4040
JsonDataObjects,
41+
System.SysConst,
4142
MVCFramework.Commons,
4243
MVCFramework.Serializer.JsonDataObjects;
4344

@@ -169,7 +170,6 @@ TMVCGUIDSerializer = class(TInterfacedObject, IMVCTypeSerializer)
169170
implementation
170171

171172
uses
172-
System.SysConst,
173173
Data.DB,
174174
MVCFramework.DuckTyping,
175175
System.Generics.Collections,

sources/MVCFramework.pas

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,8 @@ implementation
13301330
MVCFramework.Serializer.HTML,
13311331
MVCFramework.Serializer.Abstract,
13321332
MVCFramework.Utils,
1333-
MVCFramework.Serializer.Text;
1333+
MVCFramework.Serializer.Text,
1334+
MVCFramework.Validation;
13341335

13351336
var
13361337
gIsShuttingDown: Boolean = False;
@@ -2756,6 +2757,9 @@ function TMVCEngine.ExecuteAction(const ASender: TObject; const ARequest: TWebRe
27562757
lInvokeResult: TValue;
27572758
lRespStatus: Integer;
27582759
lRouterResult: TMVCRouterResult;
2760+
lEValidException: EMVCValidationException;
2761+
lValidationErrorsStr: string;
2762+
lValidationError: TPair<string, string>;
27592763
begin
27602764
Result := False;
27612765

@@ -3014,15 +3018,36 @@ function TMVCEngine.ExecuteAction(const ASender: TObject; const ARequest: TWebRe
30143018
end;
30153019
if not CustomExceptionHandling(E, lSelectedController, lContext) then
30163020
begin
3017-
Log.Error('[%s] %s [PathInfo "%s"] - %d %s (Custom message: "%s")',
3018-
[
3019-
E.Classname,
3020-
E.Message,
3021-
GetRequestShortDescription(ARequest),
3022-
E.HTTPStatusCode,
3023-
HTTP_STATUS.ReasonStringFor(E.HTTPStatusCode),
3024-
E.DetailedMessage
3025-
], LOGGERPRO_TAG);
3021+
if E is EMVCValidationException then
3022+
begin
3023+
lEValidException := EMVCValidationException(E);
3024+
lValidationErrorsStr := '';
3025+
for lValidationError in lEValidException.ValidationErrors do
3026+
begin
3027+
if lValidationErrorsStr <> '' then
3028+
lValidationErrorsStr := lValidationErrorsStr + '; ';
3029+
lValidationErrorsStr := lValidationErrorsStr + lValidationError.Key + ': ' + lValidationError.Value;
3030+
end;
3031+
Log.Warn('[%s] %s [PathInfo "%s"] - %d %s (Validation Errors: "%s")',
3032+
[
3033+
lEValidException.Classname,
3034+
lEValidException.Message,
3035+
GetRequestShortDescription(ARequest),
3036+
lEValidException.HTTPStatusCode,
3037+
HTTP_STATUS.ReasonStringFor(lEValidException.HTTPStatusCode),
3038+
lValidationErrorsStr
3039+
], LOGGERPRO_TAG)
3040+
end
3041+
else
3042+
Log.Error('[%s] %s [PathInfo "%s"] - %d %s (Custom message: "%s")',
3043+
[
3044+
E.Classname,
3045+
E.Message,
3046+
GetRequestShortDescription(ARequest),
3047+
E.HTTPStatusCode,
3048+
HTTP_STATUS.ReasonStringFor(E.HTTPStatusCode),
3049+
E.DetailedMessage
3050+
], LOGGERPRO_TAG);
30263051
if Assigned(lSelectedController) then
30273052
begin
30283053
lSelectedController.ResponseStatus(E.HTTPStatusCode);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
const
2-
DMVCFRAMEWORK_VERSION = '3.4.3-aluminium';
2+
DMVCFRAMEWORK_VERSION = '3.5.0-silicon-beta';

0 commit comments

Comments
 (0)