]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: server: globally handle configuration validation errors
authorAleš Mrázek <ales.mrazek@nic.cz>
Wed, 27 Nov 2024 10:38:25 +0000 (11:38 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 3 Dec 2024 07:53:33 +0000 (08:53 +0100)
python/knot_resolver/manager/server.py

index fbfef244234ee0204011247f28822acc85e92ba7..b09ff7b99a234440d43bc68535c726579280e9ad 100644 (file)
@@ -60,8 +60,8 @@ async def error_handler(request: web.Request, handler: Any) -> web.Response:
 
     try:
         return await handler(request)
-    except DataValidationError as e:
-        return web.Response(text=f"validation of configuration failed:\n{e}", status=HTTPStatus.BAD_REQUEST)
+    except (AggregateDataValidationError, DataValidationError) as e:
+        return web.Response(text=str(e), status=HTTPStatus.BAD_REQUEST)
     except DataParsingError as e:
         return web.Response(text=f"request processing error:\n{e}", status=HTTPStatus.BAD_REQUEST)
     except KresManagerException as e:
@@ -262,16 +262,7 @@ class Server:
 
     async def _handler_cache_clear(self, request: web.Request) -> web.Response:
         data = parse_from_mime_type(await request.text(), request.content_type)
-
-        try:
-            config = CacheClearRPCSchema(data)
-        except (AggregateDataValidationError, DataValidationError) as e:
-            return web.Response(
-                body=e,
-                status=HTTPStatus.BAD_REQUEST,
-                content_type="text/plain",
-                charset="utf8",
-            )
+        config = CacheClearRPCSchema(data)
 
         _, result = await command_single_registered_worker(config.render_lua())
         return web.Response(