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
I generally don't believe in setting the HTTP status to anything other than 200 when errors are returned. I know some people will argue the point, and that's okay.
I think the default status code for jsonrpc.excetions.Error should be configurable from the settings file.
What I'm doing now is adding a decorator (after the jsonrpc_method decorator) that catches exceptions and remakes them into json-rpc exceptions with a 200 status.
def json_convert_exception(func):
"""When calling any function, catch any non-json-rpc error and make an OtherError from it."""
def decorator(*args, **kwargs):
try:
return func(*args, **kwargs)
except jsonrpc.exceptions.Error:
raise # re-raise the error if it was already a json-rpc error
except Exception as ex:
jsonEx = jsonrpc.exceptions.OtherError( str(ex) )
if (hasattr(ex, 'code')):
jsonEx.code = ex.code
jsonEx.status = 200
raise jsonEx, None, sys.exc_info()[2] # new exception, old stacktrace
return decorator
The text was updated successfully, but these errors were encountered:
I generally don't believe in setting the HTTP status to anything other than 200 when errors are returned. I know some people will argue the point, and that's okay.
I think the default status code for jsonrpc.excetions.Error should be configurable from the settings file.
What I'm doing now is adding a decorator (after the jsonrpc_method decorator) that catches exceptions and remakes them into json-rpc exceptions with a 200 status.
The text was updated successfully, but these errors were encountered: