Error management

Catching Errors

Internal errors

When an internal/connection error occur (network error, JSON parsing error, failed to convert to expected class, ...), the JSONRPCResponseHandler will forward the error in the following order:

This way, if you don't implement methodCall:shouldForwardConnectionError: in the delegate object that expect the response, it will fall back to the implementation of the JSONRPCService's delegate to handle generic cases (which typically display an alert or something).

If you want to catch the error on specific cases, you still can implement methodCall:shouldForwardConnectionError: in the JSONRPCResponseHandler's delegate object to catch it. At this point, you can return YES to still execute the default behavior (the one in your JSONRPCService's delegate implementation) or return NO to avoid forwarding the error.

Server errors

For error returned by the server (a JSON is received but it contains an "error" object), indicating something went wrong in the server (unknown method name, bad parameters, method-specific errors, ...), this object is simply passed as an NSError in the third parameter of the JSONRPCResponseHandler's delegate callback.

The different error cases and their error domains

Internal errors ("methodCall:shouldForwardConnectionError:")

This method can receive these kinds of errors:

Server errors ("methodCall:didReturn:error:")

This section only receive error that comes directly from the WebService you query using JSON-RPC. When the server returned an error in its JSON response, this is obviously a server-dependant error code.

Note:
JSON-RPC v2.0 WebServices should return the error at the following format, according to the specification:
 {
    code: // A Number that indicates the error type that occurred. See also reserved codes at http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
    message: // A String providing a short description of the error. The message SHOULD be limited to a concise single sentence.
    data: // A value that contains additional information about the error. Defined by the Server (e.g. detailed error information, nested errors etc.).
 }
Actually, even some JSON-RPC v1.0 WebServices also return error objects using this convention. In such case, this JSON object is still available the JSONRPCErrorJSONObjectKey, but in addition:
  • The value in 'code' is used as the code of the NSError
  • The value in 'message' is used as the localizedDescription of the NSError
  • The value in 'data' can be retrieved with the @property data of NSError (see NSError(JSON))
Generated on Tue Mar 22 22:27:19 2011 for JSONRPC Framework by  doxygen 1.6.3