add errors handling
This commit is contained in:
parent
cc8d5d4189
commit
719d605e79
@ -1,7 +1,8 @@
|
||||
from flask import Blueprint
|
||||
|
||||
api = Blueprint("api",__name__)
|
||||
api = Blueprint("api", __name__)
|
||||
|
||||
from .errors import *
|
||||
from .appointement import *
|
||||
from .planning import *
|
||||
from .service import *
|
||||
|
22
ITPlanning/api/errors.py
Normal file
22
ITPlanning/api/errors.py
Normal file
@ -0,0 +1,22 @@
|
||||
from pony.orm import rollback
|
||||
from pony.orm import ObjectNotFound
|
||||
from .exception import ServerError, NotFound, GenericError
|
||||
from . import api
|
||||
|
||||
|
||||
@api.errorhandler(ValueError)
|
||||
def value_error(e):
|
||||
rollback()
|
||||
return GenericError("{0.__class__.__name__}: {0}".format(e))
|
||||
|
||||
|
||||
@api.errorhandler(ObjectNotFound)
|
||||
def object_not_found(e):
|
||||
rollback()
|
||||
return NotFound(e.entity.__name__)
|
||||
|
||||
|
||||
@api.errorhandler(500)
|
||||
def generic_error(e): # pragma: nocover
|
||||
rollback()
|
||||
return ServerError("{0.__class__.__name__}: {0}".format(e))
|
Loading…
Reference in New Issue
Block a user