Exemplo n.º 1
0
def not_found_handler(error):
    """Custom error handler for 404."""
    data = {'message': MESSAGES.get('RESOURCE_NOT_FOUND')}

    response = Response(json.dumps(data),
                        status=CODES.get('NOT_FOUND'),
                        mimetype=MIME_TYPES.get('APPLICATION_JSON'))
    return response
def bad_request(error=None):
    """handle app's 400 error"""
    resp = Response(json.dumps({
        "message": MESSAGES.get('BAD_REQUEST'),
        "status_code": RESPONSES.get('BAD_REQUEST')
    }),
                    status=RESPONSES.get('BAD_REQUEST'),
                    mimetype=MIME_TYPES.get('JSON'))
    return resp
def not_found(error=None):
    """handle app's 404 error."""
    resp = Response(json.dumps({
        "message": MESSAGES.get('NOT_FOUND'),
        "status_code": RESPONSES.get('NOT_FOUND')
    }),
                    status=RESPONSES.get('NOT_FOUND'),
                    mimetype=MIME_TYPES.get('JSON'))
    return resp
def method_not_allowed(error=None):
    """handle app's 405 error"""
    resp = Response(json.dumps({
        "message":
        MESSAGES.get('METHOD_NOT_ALLOWED'),
        "status_code":
        RESPONSES.get('METHOD_NOT_ALLOWED')
    }),
                    status=RESPONSES.get('METHOD_NOT_ALLOWED'),
                    mimetype=MIME_TYPES.get('JSON'))
    return resp
def internal_error(error=None):
    """handle app's 500 error"""
    resp = Response(json.dumps({
        "message":
        MESSAGES.get('INTERNAL_SERVER_ERROR'),
        "status_code":
        RESPONSES.get('INTERNAL_SERVER_ERROR')
    }),
                    status=RESPONSES.get('INTERNAL_SERVER_ERROR'),
                    mimetype=MIME_TYPES.get('JSON'))
    return resp