You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hüseyin Uslu edited this page Jun 3, 2014
·
1 revision
There are multiple ways to control exceptions that are returned from your method.
The default behavior is that any exception thrown in your method will be returned to the client in its entirety (stack trace, everything)
There is a global hook you can use to manage exceptions before they are returned to the client. As early as possible you will want to call AustinHarris.JsonRpc.Config.SetErrorHandler(). In asp.net you should do this in Application_Start. The signature for this method is
Here is where you would add your global error logging. Here you can clean up the exception, maybe you don't want to return the stack trace, or watson buckets.
You can also explicitly throw the exception how you want to in the first place. If you throw a JsonRpcException from within your JsonRpcMethod then it will be returned to the client exactly as you specify it;
[JsonRpcMethod("error3")]privatestringthrowsException2(strings){thrownewJsonRpcException(-27000,"This exception was thrown using: throw new JsonRpcException()",null);returns;}
Setting the exception without throwing one.
If you don't want to throw an exception at all but still want to control the error response to the client you can make a call to JsonRpcContext.SetException().
[JsonRpcMethod("error4")]privatestringthrowsException3(strings){JsonRpcContext.SetException(newJsonRpcException(-27000,"This exception was thrown using: JsonRpcContext.SetException()",null));returnnull;}
It is up to the developer to stop execution of the current method when using this approach.