2022-06-06 21:30:30 +02:00
|
|
|
import json
|
2022-05-19 18:15:11 +02:00
|
|
|
from typing import Tuple
|
|
|
|
|
2022-06-06 21:30:30 +02:00
|
|
|
from apiflask import APIFlask
|
|
|
|
from werkzeug.exceptions import RequestEntityTooLarge, HTTPException
|
2022-05-19 18:15:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
def request_entity_too_large(error: RequestEntityTooLarge) -> Tuple[dict, int]:
|
|
|
|
return {'error': 'File too large!'}, 413
|
2022-06-06 21:30:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
def register_error_handlers(app: APIFlask):
|
|
|
|
@app.errorhandler(HTTPException)
|
|
|
|
def handle_http_exception(e):
|
|
|
|
response = e.get_response()
|
|
|
|
response.data = json.dumps({'error': e.description})
|
|
|
|
response.content_type = 'application/json'
|
|
|
|
return response
|