Esempio n. 1
0
    def from_exception(cls, ex):
        if isinstance(ex, http.HTTPError):
            code = ex.status_code
        elif isinstance(ex, error.FeatError):
            code = ex.eror_code
        else:
            code = None

        if isinstance(ex, error.FeatError):
            message = ex.error_name
        else:
            message = str(ex)

        if not message:
            message = type(ex).__name__

        debug = error.get_exception_message(ex)
        trace = error.get_exception_traceback(ex)

        return cls(code=code, message=message, debug=debug, trace=trace)
Esempio n. 2
0
    def from_exception(cls, ex):
        error_type = ErrorTypes.generic
        status_code = None
        error_code = None
        message = None
        subjects = None
        reasons = None
        debug = None
        trace = None

        if isinstance(ex, error.FeatError):
            error_code = ex.error_code
            message = ex.error_name

        if isinstance(ex, http.HTTPError):
            error_type = ErrorTypes.http
            status_code = ex.status_code
            if error_code is None:
                error_code = int(status_code)

        if isinstance(ex, ParameterError):
            error_type = ex.error_type
            status_code = http.Status.BAD_REQUEST
            subjects = ex.parameters
            if isinstance(ex, InvalidParameters):
                reasons = ex.reasons

        if not message:
            message = str(ex) or type(ex).__name__

        if not isinstance(ex, http.HTTPError):
            debug = str(ex)
            trace = error.get_exception_traceback(ex)

        return cls(error_type=error_type, error_code=error_code,
                   status_code=status_code, message=message,
                   subjects=subjects, reasons=reasons,
                   debug=debug, trace=trace)