notify-api-412 use black to enforce python style standards

This commit is contained in:
Kenneth Kehl
2023-08-23 10:35:43 -07:00
parent a7898118d7
commit 026dc14021
586 changed files with 33990 additions and 23461 deletions

View File

@@ -12,7 +12,7 @@ from app.errors import InvalidRequest
class TooManyRequestsError(InvalidRequest):
status_code = 429
message_template = 'Exceeded send limits ({}) for today'
message_template = "Exceeded send limits ({}) for today"
def __init__(self, sending_limit):
self.message = self.message_template.format(sending_limit)
@@ -20,7 +20,7 @@ class TooManyRequestsError(InvalidRequest):
class TotalRequestsError(InvalidRequest):
status_code = 429
message_template = 'Exceeded total application limits ({}) for today'
message_template = "Exceeded total application limits ({}) for today"
def __init__(self, sending_limit):
self.message = self.message_template.format(sending_limit)
@@ -28,15 +28,19 @@ class TotalRequestsError(InvalidRequest):
class RateLimitError(InvalidRequest):
status_code = 429
message_template = 'Exceeded rate limit for key type {} of {} requests per {} seconds'
message_template = (
"Exceeded rate limit for key type {} of {} requests per {} seconds"
)
def __init__(self, sending_limit, interval, key_type):
# normal keys are spoken of as "live" in the documentation
# so using this in the error messaging
if key_type == 'normal':
key_type = 'live'
if key_type == "normal":
key_type = "live"
self.message = self.message_template.format(key_type.upper(), sending_limit, interval)
self.message = self.message_template.format(
key_type.upper(), sending_limit, interval
)
class BadRequestError(InvalidRequest):
@@ -63,8 +67,13 @@ def register_errors(blueprint):
# Please not that InvalidEmailError is re-raised for InvalidEmail or InvalidPhone,
# work should be done in the utils app to tidy up these errors.
current_app.logger.info(error)
return jsonify(status_code=400,
errors=[{"error": error.__class__.__name__, "message": str(error)}]), 400
return (
jsonify(
status_code=400,
errors=[{"error": error.__class__.__name__, "message": str(error)}],
),
400,
)
@blueprint.errorhandler(InvalidRequest)
def invalid_data(error):
@@ -81,16 +90,35 @@ def register_errors(blueprint):
@blueprint.errorhandler(DataError)
def no_result_found(e):
current_app.logger.info(e)
return jsonify(status_code=404,
errors=[{"error": e.__class__.__name__, "message": "No result found"}]), 404
return (
jsonify(
status_code=404,
errors=[{"error": e.__class__.__name__, "message": "No result found"}],
),
404,
)
@blueprint.errorhandler(AuthError)
def auth_error(error):
current_app.logger.info('API AuthError, client: {} error: {}'.format(request.headers.get('User-Agent'), error))
current_app.logger.info(
"API AuthError, client: {} error: {}".format(
request.headers.get("User-Agent"), error
)
)
return jsonify(error.to_dict_v2()), error.code
@blueprint.errorhandler(Exception)
def internal_server_error(error):
current_app.logger.exception(error)
return jsonify(status_code=500,
errors=[{"error": error.__class__.__name__, "message": 'Internal server error'}]), 500
return (
jsonify(
status_code=500,
errors=[
{
"error": error.__class__.__name__,
"message": "Internal server error",
}
],
),
500,
)