# HG changeset patch # User Goffi # Date 1679154801 -3600 # Node ID 4ef47311649961ba2ea66e0c165d3e01f7991b42 # Parent b13673d998dc902c05e7de55b42aaa1305f1998b component AP gateway (http): handle properly NotFound error: When an `exceptions.NotFound` is received, log a warning message and return the appropriate HTTP code instead of raising the default `exceptions.InternalError`. diff -r b13673d998dc -r 4ef473116499 sat/plugins/plugin_comp_ap_gateway/__init__.py --- a/sat/plugins/plugin_comp_ap_gateway/__init__.py Sat Mar 18 16:20:30 2023 +0100 +++ b/sat/plugins/plugin_comp_ap_gateway/__init__.py Sat Mar 18 16:53:21 2023 +0100 @@ -474,7 +474,7 @@ try: found_item = found_items[0] except IndexError: - raise exceptions.NotFound("requested items can't be found") + raise exceptions.NotFound(f"requested item at {url} can't be found") if node.startswith(self._events.namespace): # this is an event diff -r b13673d998dc -r 4ef473116499 sat/plugins/plugin_comp_ap_gateway/http_server.py --- a/sat/plugins/plugin_comp_ap_gateway/http_server.py Sat Mar 18 16:20:30 2023 +0100 +++ b/sat/plugins/plugin_comp_ap_gateway/http_server.py Sat Mar 18 16:53:21 2023 +0100 @@ -78,14 +78,24 @@ request.setResponseCode(http_code, None if msg is None else msg.encode()) def _onRequestError(self, failure_: failure.Failure, request: "HTTPRequest") -> None: - log.exception(f"Internal error: {failure_.value}") - self.responseCode( - request, - http.INTERNAL_SERVER_ERROR, - f"internal error: {failure_.value}" - ) + exc = failure_.value + if isinstance(exc, exceptions.NotFound): + self.responseCode( + request, + http.NOT_FOUND, + str(exc) + ) + else: + log.exception(f"Internal error: {failure_.value}") + self.responseCode( + request, + http.INTERNAL_SERVER_ERROR, + f"internal error: {failure_.value}" + ) + request.finish() + raise failure_ + request.finish() - raise failure_ async def webfinger(self, request): url_parsed = parse.urlparse(request.uri.decode())