fixed improper error handling when data is not valid JSON (#1326)

This commit is contained in:
hackrush 2018-07-30 19:08:36 +05:30 committed by Lex Berezhny
parent 88b8ca8a49
commit 9ab256df30
2 changed files with 5 additions and 4 deletions

View file

@ -14,7 +14,7 @@ at anytime.
### Fixed ### Fixed
* loggly error reporting not following `share_usage_data` * loggly error reporting not following `share_usage_data`
* * improper error handling when data is not valid JSON
### Deprecated ### Deprecated
* automatic claim renew, this is no longer needed * automatic claim renew, this is no longer needed

View file

@ -298,12 +298,13 @@ class AuthJSONRPCServer(AuthorizedBase):
# maybe its a twisted Failure with another type of error # maybe its a twisted Failure with another type of error
error = JSONRPCError(failure.getErrorMessage() or failure.type.__name__, error = JSONRPCError(failure.getErrorMessage() or failure.type.__name__,
traceback=failure.getTraceback()) traceback=failure.getTraceback())
else:
# last resort, just cast it as a string
error = JSONRPCError(str(failure))
if not failure.check(ComponentsNotStarted, ComponentStartConditionNotMet): if not failure.check(ComponentsNotStarted, ComponentStartConditionNotMet):
log.warning("error processing api request: %s\ntraceback: %s", error.message, log.warning("error processing api request: %s\ntraceback: %s", error.message,
"\n".join(error.traceback)) "\n".join(error.traceback))
else:
# last resort, just cast it as a string
error = JSONRPCError(str(failure))
response_content = jsonrpc_dumps_pretty(error, id=id_) response_content = jsonrpc_dumps_pretty(error, id=id_)
self._set_headers(request, response_content) self._set_headers(request, response_content)
request.setResponseCode(200) request.setResponseCode(200)