mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-15 09:42:38 -05:00
Start building up the validators required for post notificaiton. The app/v2/errors.py is a rough sketch, will be passed a code, the error can look up the message and link for the error message.
30 lines
724 B
Python
30 lines
724 B
Python
from flask import jsonify
|
|
|
|
from app.errors import InvalidRequest
|
|
|
|
|
|
class BadRequestError(Exception):
|
|
status_code = 400
|
|
|
|
def __init__(self, message, fields, code):
|
|
self.code = code
|
|
self.message = message
|
|
self.fields = fields
|
|
|
|
|
|
def register_errors(blueprint):
|
|
@blueprint.app_errorhandler(Exception)
|
|
def authentication_error(error):
|
|
# v2 error format - NOT this
|
|
return jsonify(result='error', message=error.message), error.code
|
|
|
|
@blueprint.app_errorhandler(InvalidRequest)
|
|
def handle_invalid_request(error):
|
|
# {
|
|
# "code",
|
|
# "link",
|
|
# "message" ,
|
|
# "fields":
|
|
# }
|
|
return "build_error_message"
|