-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Handle NotFound and UnprocessableEntity errors in middleware (#3327)
* ✨ Handle NotFound and UnprocessableEntity exceptions at info log level Signed-off-by: ff137 <[email protected]> * 🎨 replace traceback print with exception log Signed-off-by: ff137 <[email protected]> * 🎨 replace deprecated .warn with .warning Signed-off-by: ff137 <[email protected]> * 🎨 setting ledger to read-only should not print error log Signed-off-by: ff137 <[email protected]> * ✨ extract the marshmallow validation error message from the nested exception Signed-off-by: ff137 <[email protected]> * 🎨 modify import for consistency Signed-off-by: ff137 <[email protected]> * ✅ test coverage for new method Signed-off-by: ff137 <[email protected]> * ✅ test coverage for exception handling changes Signed-off-by: ff137 <[email protected]> * 🎨 refactor for reduced complexity Signed-off-by: ff137 <[email protected]> * 🎨 reorder exceptions by severity Signed-off-by: ff137 <[email protected]> * 🎨 update log level Signed-off-by: ff137 <[email protected]> * 🎨 Signed-off-by: ff137 <[email protected]> --------- Signed-off-by: ff137 <[email protected]> Co-authored-by: jamshale <[email protected]>
- Loading branch information
Showing
7 changed files
with
308 additions
and
43 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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""Extract validation error messages from nested exceptions.""" | ||
|
||
from aiohttp.web import HTTPUnprocessableEntity | ||
from marshmallow.exceptions import ValidationError | ||
|
||
|
||
def extract_validation_error_message(exc: HTTPUnprocessableEntity) -> str: | ||
"""Extract marshmallow error message from a nested UnprocessableEntity exception.""" | ||
visited = set() | ||
current_exc = exc | ||
while current_exc and current_exc not in visited: | ||
visited.add(current_exc) | ||
if isinstance(current_exc, ValidationError): | ||
return current_exc.messages | ||
current_exc = current_exc.__cause__ or current_exc.__context__ | ||
return exc.reason |
Oops, something went wrong.