mirror of https://github.com/stijndcl/didier
Clean up error handlers
parent
6ba104758b
commit
66d6e2480f
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue