23 lines
535 B
Python
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))
|