src/dirbs/api/__init__.py
def app_error_handler(error: callable) -> Union[BadRequest, callable, callable]:
    """
    Make sure we log metrics for all failures.

    Arguments:
        error: http error response object
    Raises:
        error: In debug mode, any non-HTTP exceptions to trigger the debugger
    Returns:
        BadRequest: if error contains status code 422
        JSON error: if any other code or error
        InternalServerError: if any internal server error
    """
    if isinstance(error, HTTPException):
        code = 400 if error.code == 422 else error.code
    else:
        code = 500

    metrics_api_type = _metrics_type_from_req_ctxt(request)
    statsd.incr('dirbs.api.failures.{0}.{1}'.format(metrics_api_type, code))
    if code == 500:
        # Log exception to the dirbs.exception logger
        logger = logging.getLogger('dirbs.exception')
        logger.error('DIRBS encountered an uncaught software exception', exc_info=sys.exc_info())
        statsd.incr('dirbs.exceptions.api.{0}'.format(metrics_api_type))

    # Send a 400 response back if query parameter validation fails.
    if isinstance(error, HTTPException) and error.code == 422:
        return BadRequest(description=error.exc.messages)

    if isinstance(error, HTTPException):
        return error.get_response(environ=None), code
    elif app.propagate_exceptions:
        # In debug or testing mode, re-raise any non-HTTP exceptions to trigger the debugger
        raise error
    else:
        return InternalServerError().get_response()

    Make sure we log metrics for all failures.

    Arguments:
        error: http error response object
    Raises:
        error: In debug mode, any non-HTTP exceptions to trigger the debugger
    Returns:
        BadRequest: if error contains status code 422
        JSON error: if any other code or error
        InternalServerError: if any internal server error
    
Make sure we log metrics for all failures.
Make sure we log metrics for all failures .
def app_error_handler(error: callable) -> Union[BadRequest, callable, callable]:
    if isinstance(error, HTTPException):
        code = 400 if error.code == 422 else error.code
    else:
        code = 500
    metrics_api_type = _metrics_type_from_req_ctxt(request)
    statsd.incr('dirbs.api.failures.{0}.{1}'.format(metrics_api_type, code))
    if code == 500:
        logger = logging.getLogger('dirbs.exception')
        logger.error('DIRBS encountered an uncaught software exception', exc_info=sys.exc_info())
        statsd.incr('dirbs.exceptions.api.{0}'.format(metrics_api_type))
    if isinstance(error, HTTPException) and error.code == 422:
        return BadRequest(description=error.exc.messages)
    if isinstance(error, HTTPException):
        return error.get_response(environ=None), code
    elif app.propagate_exceptions:
        raise error
    else:
        return InternalServerError().get_response()
def app_error_handler ( error : callable ) -> Union [ BadRequest , callable , callable ] : if isinstance ( error , HTTPException ) : code = 400 if error . code == 422 else error . code else : code = 500 metrics_api_type = _metrics_type_from_req_ctxt ( request ) statsd . incr ( 'dirbs.api.failures.{0}.{1}' . format ( metrics_api_type , code ) ) if code == 500 : logger = logging . getLogger ( 'dirbs.exception' ) logger . error ( 'DIRBS encountered an uncaught software exception' , exc_info = sys . exc_info ( ) ) statsd . incr ( 'dirbs.exceptions.api.{0}' . format ( metrics_api_type ) ) if isinstance ( error , HTTPException ) and error . code == 422 : return BadRequest ( description = error . exc . messages ) if isinstance ( error , HTTPException ) : return error . get_response ( environ = None ) , code elif app . propagate_exceptions : raise error else : return InternalServerError ( ) . get_response ( )
Make sure we log metrics for all failures.
Make sure we log metrics for all failures .
"""
    Make sure we log metrics for all failures.

    Arguments:
        error: http error response object
    Raises:
        error: In debug mode, any non-HTTP exceptions to trigger the debugger
    Returns:
        BadRequest: if error contains status code 422
        JSON error: if any other code or error
        InternalServerError: if any internal server error
    """ # Log exception to the dirbs.exception logger # Send a 400 response back if query parameter validation fails. # In debug or testing mode, re-raise any non-HTTP exceptions to trigger the debugger
if error contains status code 422
JSON error: if any other code or error
InternalServerError: if any internal server error
if error contains status code 422 JSON error : if any other code or error InternalServerError : if any internal server error
BadRequest
In debug mode, any non-HTTP exceptions to trigger the debugger
In debug mode any non - HTTP exceptions to trigger the debugger
error
error
callable
http error response object
http error response object