Feat(API): ensuring error responses are JSON
This commit is contained in:
parent
3a870ed2c5
commit
7815894d9f
@ -1,9 +1,21 @@
|
||||
from quart import Quart
|
||||
from quart import Quart, ResponseReturnValue
|
||||
from backend.blueprints.control import blueprint as control_blueprint
|
||||
|
||||
from backend.lib.api_error import APIError
|
||||
|
||||
|
||||
app = Quart(__name__)
|
||||
app.config.from_prefixed_env(prefix="TODO")
|
||||
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user