-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Although nothing is currently stored in the class instance, this change just allows the app registration to be done after instantiation.
- Loading branch information
Showing
5 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
from flask import jsonify | ||
|
||
|
||
class ValidationException(Exception): | ||
def __init__(self, errors): | ||
self.errors = errors | ||
|
||
|
||
def register_error_handler(app): | ||
def validations_error_handler(ex): | ||
return jsonify({ | ||
'success': False, | ||
'message': 'Validation error', | ||
response = { | ||
'message': app.config.get('SIEVE_RESPONSE_MESSAGE', 'Validation error'), | ||
'errors': ex.errors | ||
}), 400 | ||
} | ||
|
||
if app.config.get('SIEVE_INCLUDE_SUCCESS_KEY'): | ||
response['success'] = False | ||
|
||
if app.config.get('SIEVE_RESPONSE_WRAPPER'): | ||
response = {app.config.get('SIEVE_RESPONSE_WRAPPER'): response} | ||
|
||
return jsonify(response), app.config.get('SIEVE_INVALID_STATUS_CODE', 400) | ||
|
||
app.register_error_handler( | ||
ValidationException, | ||
validations_error_handler | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters