Skip to content

Commit 50f9936

Browse files
committed
Only propagate HTTP exceptions
This responds to @jtc42's comment, and reverts to the old behaviour except for HTTPErrors, i.e. it allows `abort` and validation errors to change the return code, but other errors use the existing behaviour.
1 parent e87152d commit 50f9936

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/labthings/views/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from flask.views import MethodView
77
from typing_extensions import Protocol
88
from werkzeug.wrappers import Response as ResponseBase
9+
from werkzeug.exceptions import HTTPException
910

1011
from ..actions.pool import Pool
1112
from ..deque import Deque
@@ -234,12 +235,12 @@ def dispatch_request(self, *args, **kwargs):
234235
if task.output and isinstance(task.output, ResponseBase):
235236
return self.represent_response((task.output, 200))
236237

237-
# If the action fails quickly, propagate the exception.
238+
# If the action fails quickly with an HTTPException, propagate it.
238239
# This allows us to handle validation errors nicely.
239-
# TODO: do we want to do this for all exceptions, or just
240-
# werkzeug.exceptions.HTTPException instances?
241-
if task._exception is not None:
242-
raise task._exception
240+
# Similarly, calling Flask's `abort(404)` will work during the
241+
# timeout period, as it uses the same mechanism.
242+
if task.exception and isinstance(task.exception, HTTPException):
243+
raise task.exception
243244

244245
return self.represent_response((ActionSchema().dump(task), 201))
245246

0 commit comments

Comments
 (0)