Feat(API): ensuring error responses are JSON

This commit is contained in:
minhtrannhat 2022-11-19 14:12:41 -05:00
parent 3a870ed2c5
commit 7815894d9f
No known key found for this signature in database
GPG Key ID: 894C6A5801E01CA9

View File

@ -1,9 +1,21 @@
from quart import Quart from quart import Quart, ResponseReturnValue
from backend.blueprints.control import blueprint as control_blueprint from backend.blueprints.control import blueprint as control_blueprint
from backend.lib.api_error import APIError
app = Quart(__name__) app = Quart(__name__)
app.config.from_prefixed_env(prefix="TODO") app.config.from_prefixed_env(prefix="TODO")
app.register_blueprint(control_blueprint) app.register_blueprint(control_blueprint)
@app.errorhandler(APIError) # type: ignore
async def handle_api_error(error: APIError) -> ResponseReturnValue:
return {"code": error.code}, error.status_code
@app.errorhandler(500)
async def handle_generic_error(error: Exception) -> ResponseReturnValue:
return {"code": "INTERNAL_SERVER_ERROR"}, 500