itplanning/ITPlanning/api/errors.py

23 lines
535 B
Python
Raw Permalink Normal View History

2021-05-30 09:05:19 +00:00
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))