diff --git a/swh/scheduler/api/client.py b/swh/scheduler/api/client.py --- a/swh/scheduler/api/client.py +++ b/swh/scheduler/api/client.py @@ -7,6 +7,7 @@ from swh.core.api import RPCClient from .serializers import ENCODERS, DECODERS +from .. import exc from ..interface import SchedulerInterface @@ -17,5 +18,7 @@ backend_class = SchedulerInterface + reraise_exceptions = [getattr(exc, a) for a in exc.__all__] + extra_type_decoders = DECODERS extra_type_encoders = ENCODERS diff --git a/swh/scheduler/api/server.py b/swh/scheduler/api/server.py --- a/swh/scheduler/api/server.py +++ b/swh/scheduler/api/server.py @@ -12,6 +12,7 @@ from swh.core.api import error_handler, negotiate from swh.scheduler import get_scheduler +from swh.scheduler.exc import SchedulerException from swh.scheduler.interface import SchedulerInterface from .serializers import ENCODERS, DECODERS @@ -36,6 +37,11 @@ ) +@app.errorhandler(SchedulerException) +def argument_error_handler(exception): + return error_handler(exception, encode_data, status_code=400) + + @app.errorhandler(Exception) def my_error_handler(exception): return error_handler(exception, encode_data) diff --git a/swh/scheduler/exc.py b/swh/scheduler/exc.py new file mode 100644 --- /dev/null +++ b/swh/scheduler/exc.py @@ -0,0 +1,12 @@ +# Copyright (C) 2020 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +__all__ = [ + "SchedulerException", +] + + +class SchedulerException(Exception): + pass