itplanning/ITPlanning/api/errors.py
2021-05-30 11:05:19 +02:00

23 lines
535 B
Python

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))