| Conditions | 4 |
| Total Lines | 21 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import json |
||
| 9 | def broad_exception_handler(e: Exception): |
||
| 10 | # TODO 에러를 세분화해서 잡는 것을 추천합니다. |
||
| 11 | |||
| 12 | if isinstance(e, HTTPException): |
||
| 13 | message = e.description |
||
| 14 | code = e.code |
||
| 15 | |||
| 16 | elif isinstance(e, ValidationError): |
||
| 17 | message = json.loads(e.json()) |
||
| 18 | code = HTTPStatus.BAD_REQUEST |
||
| 19 | |||
| 20 | else: |
||
| 21 | message = "" |
||
| 22 | code = HTTPStatus.INTERNAL_SERVER_ERROR |
||
| 23 | |||
| 24 | if current_app.debug: |
||
| 25 | import traceback |
||
| 26 | |||
| 27 | traceback.print_exc() |
||
| 28 | |||
| 29 | return jsonify({"error": message}), code |
||
| 30 |