Skip to content

Commit

Permalink
manager: server: globally handle configuration validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alesmrazek committed Nov 27, 2024
1 parent b3169ab commit a333fb3
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions python/knot_resolver/manager/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -262,16 +262,7 @@ async def _handler_metrics_prometheus(self, _request: web.Request) -> web.Respon

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(
Expand Down

0 comments on commit a333fb3

Please sign in to comment.