Conditions | 1 |
Total Lines | 21 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | from flask import Blueprint, Flask |
||
5 | def route(flask_app: Flask): |
||
6 | from app.views.sample.api import SampleAPI |
||
7 | |||
8 | handle_exception_func = flask_app.handle_exception |
||
9 | handle_user_exception_func = flask_app.handle_user_exception |
||
10 | # register_blueprint 시 defer되었던 함수들이 호출되며, flask-restful.Api._init_app()이 호출되는데 |
||
11 | # 해당 메소드가 app 객체의 에러 핸들러를 오버라이딩해서, 별도로 적용한 handler의 HTTPException 관련 로직이 동작하지 않음 |
||
12 | # 따라서 두 함수를 임시 저장해 두고, register_blueprint 이후 함수를 재할당하도록 함 |
||
13 | |||
14 | # - blueprint, api object initialize |
||
15 | api_blueprint = Blueprint("api", __name__) |
||
16 | api = Api(api_blueprint) |
||
17 | |||
18 | # - route |
||
19 | api.add_resource(SampleAPI, "/sample") |
||
20 | |||
21 | # - register blueprint |
||
22 | flask_app.register_blueprint(api_blueprint) |
||
23 | |||
24 | flask_app.handle_exception = handle_exception_func |
||
25 | flask_app.handle_user_exception = handle_user_exception_func |
||
26 |