Passed
Push — master ( 99f654...da6e57 )
by Mingyu
01:48 queued 52s
created

http_exception_handler()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
from http import HTTPStatus
2
3
from flask import current_app, jsonify
4
from pydantic import ValidationError
5
from werkzeug.exceptions import HTTPException
6
7
8
def broad_exception_handler(e: Exception):
9
    # TODO 에러를 세분화해서 잡는 것을 추천합니다.
10
11
    if isinstance(e, HTTPException):
12
        message = e.description
13
        code = e.code
14
15
    elif isinstance(e, ValidationError):
16
        message = e.errors()
17
        code = HTTPStatus.BAD_REQUEST
18
19
    else:
20
        message = ""
21
        code = HTTPStatus.INTERNAL_SERVER_ERROR
22
23
        if current_app.debug:
24
            import traceback
25
26
            traceback.print_exc()
27
28
    return jsonify({"error": message}), code
29