def _handle_request_exception(e): if not isinstance(e, HTTPError): reraise(e.exc_info()) message = e.response.body if message.endswith('\n'): message = message[:-1] if 400 <= e.code < 500: raise BadRequestError(message) raise UnexpectedError(message)
def encode_exc_info(self, exc_info): response_body = None e = exc_info[1] for exc_spec in self.result_spec.exception_specs: if isinstance(e, exc_spec.spec.surface): response_body = self.result_spec.surface(**{exc_spec.name: e}) break if response_body is not None: response_body = self.module.dumps(response_body) return Response(body=response_body) # No match. Re-raise. reraise(exc_info)
def encode_exc_info(self, exc_info): """Encodes the given failure into a response. decode_request MUST be called before encode_exc_info. encode_response and encode_exc_info SHOULD return the same kind of object. This function MAY handle the exception and return a response. If it is unable to handle the exception, it MUST re-raise the exception. The default behavior is to re-raise the exception. :param tuple exc_info: Triple of ``(class, exception, traceback)`` representing the failure. :returns yarpc.Response: Encoded response """ reraise(exc_info)