Files
notifications-api/app/v2/errors.py
Rebecca Law 8cf2fc72a8 - Refactor version 1 of post notificaitons to use the common persist_notificaiton and send_notification_to_queue methods.
- It would be nice to refactor the send_sms and send_email tasks to use these common functions as well, that way I can get rid of the new Notifications.from_v2_api_request method.
- Still not happy with the format of the errors. Would like to find a happy place, where the message is descript enough that we do not need external documentation to explain the error. Perhaps we still only need documentation to explain the trial mode concept.
2016-10-28 17:10:00 +01:00

38 lines
1.1 KiB
Python

from flask import jsonify, current_app
from app.errors import InvalidRequest
class TooManyRequestsError(InvalidRequest):
status_code = 429
# code and link will be in a static file
code = "10429"
link = "link to docs"
message_template = 'Exceeded send limits ({}) for today'
def __init__(self, sending_limit):
self.message = self.message_template.format(sending_limit)
class BadRequestError(InvalidRequest):
status_code = 400
code = "10400"
link = "link to documentation"
message = "An error occurred"
def __init__(self, fields=None, message=None):
self.fields = fields
self.message = message if message else self.message
def register_errors(blueprint):
@blueprint.errorhandler(InvalidRequest)
def invalid_data(error):
current_app.logger.error(error)
response = jsonify(error.to_dict_v2()), error.status_code
return response
@blueprint.errorhandler(Exception)
def authentication_error(error):
# v2 error format - NOT this
return jsonify(result='error', message=error.message), error.code