add errors handling

This commit is contained in:
vincent 2021-05-30 11:05:19 +02:00
parent cc8d5d4189
commit 719d605e79
2 changed files with 24 additions and 1 deletions

View File

@ -1,7 +1,8 @@
from flask import Blueprint from flask import Blueprint
api = Blueprint("api",__name__) api = Blueprint("api", __name__)
from .errors import *
from .appointement import * from .appointement import *
from .planning import * from .planning import *
from .service import * from .service import *

22
ITPlanning/api/errors.py Normal file
View 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))