Clean up error handlers

Stijn De Clercq 2021-09-06 01:39:50 +02:00
parent 6ba104758b
commit 66d6e2480f
2 changed files with 14 additions and 7 deletions

View File

@ -1,6 +1,11 @@
def handler_404(e=None):
return {"error": e or "The requested resource could not be found."}, 404
from werkzeug.exceptions import NotFound, UnprocessableEntity
def handler_422(e):
return {"error": e}, 422
def handler_404(e: NotFound):
return {"error": e.description}, 404
def handler_422(e: UnprocessableEntity):
print(e)
print(e.description)
return {"error": e.description}, 422

View File

@ -1,9 +1,11 @@
from werkzeug.exceptions import abort
from .error_handlers import handler_404, handler_422
from .routes.dm import dm_blueprint
from .routes.ping import ping_blueprint
from .routes.stats import stats_blueprint
from functions.database import custom_commands
from quart import Quart, jsonify
from quart import Quart, jsonify, Response
from quart_cors import cors
@ -36,12 +38,12 @@ async def get_custom_command(command_id):
command_id = int(command_id)
except ValueError:
# Id is not an int
return unprocessable_entity("Parameter id was not a valid integer.")
abort(422, "Parameter id was not a valid integer.")
command = custom_commands.get_by_id(command_id)
if command is None:
return handler_404("")
abort(404)
return jsonify(command)