Index: MVCFramework.JSONRPC.pas =================================================================== --- MVCFramework.JSONRPC.pas (revision 207) +++ MVCFramework.JSONRPC.pas (working copy) @@ -372,6 +372,7 @@ TMVCJSONRPCController = class(TMVCController) private + fExceptionHandler: TMVCJSONRPCExceptionHandlerProc; fSerializer: TMVCJsonDataObjectsSerializer; fRPCInstance: TObject; fOwsRPCInstance: Boolean; @@ -408,7 +409,8 @@ TMVCJSONRPCPublisher = class(TMVCJSONRPCController) public - constructor Create(const RPCInstance: TObject; const Owns: Boolean = True); reintroduce; overload; + constructor Create(const RPCInstance: TObject; const Owns: Boolean = True; ExceptionHandler: TMVCJSONRPCExceptionHandlerProc = nil); + reintroduce; overload; end; TJSONRPCProxyGenerator = class abstract @@ -821,11 +823,13 @@ { TMVCJSONRPCController } -constructor TMVCJSONRPCPublisher.Create(const RPCInstance: TObject; const Owns: Boolean); +constructor TMVCJSONRPCPublisher.Create(const RPCInstance: TObject; const Owns: Boolean = True; ExceptionHandler: + TMVCJSONRPCExceptionHandlerProc = nil); begin inherited Create; fRPCInstance := RPCInstance; fOwsRPCInstance := Owns; + fExceptionHandler := ExceptionHandler; end; // procedure TMVCJSONRPCController.CheckInputParametersTypes(aRTTIMethod: TRTTIMethod); @@ -1147,6 +1151,8 @@ lTypeAttrs: TArray; lHTTPVerb: TMVCHTTPMethodType; lAllMethodsCallableWithGET: Boolean; + lExceptionHandled: Boolean; + lJSONRespString: string; begin lBeforeCallHookHasBeenInvoked := False; lAfterCallHookHasBeenInvoked := False; @@ -1347,9 +1353,18 @@ begin lJSONResp := CreateError(lReqID, 0, Ex.Message); LogE(Format('[JSON-RPC][CLS %s][MSG "%s"]', [Ex.ClassName, Ex.Message])); + if Assigned(fExceptionHandler) then + begin + lExceptionHandled := true; + lJSONRespString := lJSONResp.ToString; + fExceptionHandler(Ex, Context, lJSONRespString, lExceptionHandled); + if not lExceptionHandled then + raise; + lJSONResp.Free; + lJSONResp := TJsonObject.Parse(lJSONRespString) as TJsonObject; + end; end; end; // except - if lBeforeCallHookHasBeenInvoked and (not lAfterCallHookHasBeenInvoked) then begin try