def _handle_request_exception(self, e):
        message = {"code": UNEXPECTED_EXCEPTION.code, "message": UNEXPECTED_EXCEPTION.message}
        http_code = 500
        
        try:
            if isinstance(e, FlamesError):
                if e.status_code.code == UNKNOWN_RESOURCE.code:
                    http_code = 404
                    self._logger.debug("Unknown resource %s %s" % (self.request.method, self.request.path))
                else:
                    http_code = 400
                    self._logger.debug("A bee exception occurs %s" % e)
                
                kwargs = encoded_string_dict(e.kwargs)
                message = {"code": e.status_code.code, "message": e.status_code.message.format(**kwargs)}
            else:
                self._logger.exception("An unexpected exception occurs.")
        except:
            self._logger.exception("An unexpected exception occurs.")
                    
        if _config.debug_mode:
            etype, value, tb = sys.exc_info()
            exceptions = traceback.format_exception(etype, value, tb)
            
            message['stacktrace'] = ''.join(exceptions[_config.debug_stacktrace_limit:])

        self.set_status(http_code)
        self.write(message)
        self.finish()
Beispiel #2
0
    def __str__(self, **kwargs):
        _return = None
        if len(self.kwargs) > 0:
            try:
                string_dict = encoded_string_dict(self.kwargs)
                _return = str(self.status_code.code) + ' : ' + self.status_code.message.format(**string_dict)
            except Exception as e:
                logger.exception('String Format Exception Occurred')

        if not _return:
            _return = str(self.status_code.code) + ' : ' + self.status_code.message
        
        return _return