def write_except(self, e): if isinstance(e, ServiceException): self.write(dict(code=e.code, msg=Errors.error_message(e.code)), 400) elif isinstance(e, ServiceError): logging.exception(e) self.write(dict(code=e.code, msg=Errors.error_message(e.code)), 500) elif isinstance(e, ServiceValidationFailsException): self.write(dict(code=e.code, field=e.field, msg=e.msg, errors=getattr(e, 'errors', '')), 400) else: pass
def write_error(self, status_code, **kwargs): if self.settings.get("serve_traceback") and "exc_info" in kwargs: # in debug mode, try to send a traceback self.set_header("Content-Type", "application/json; charset=UTF-8") self.write_except(kwargs['exc_info'][1]) self.finish() else: if "exc_info" in kwargs: self.set_header("Content-Type", "application/json; charset=UTF-8") try: self.write_except(kwargs['exc_info'][1]) except Exception: self.write(dict(code=1000, msg=Errors.error_message(1000)), 500) self.finish() else: self.write(dict(code=status_code, msg=self._reason), status_code) self.finish()