X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/dfcb24061eb6d3d415cd86d2f4edd95c4debaf36..2af20f8df88461f2593c7fa0851e3841f20d66c3:/nominatim/server/sanic/server.py diff --git a/nominatim/server/sanic/server.py b/nominatim/server/sanic/server.py index 81d62faf..15887eef 100644 --- a/nominatim/server/sanic/server.py +++ b/nominatim/server/sanic/server.py @@ -16,6 +16,7 @@ from sanic.response import text as TextResponse from nominatim.api import NominatimAPIAsync import nominatim.api.v1 as api_impl +from nominatim.config import Configuration class ParamWrapper(api_impl.ASGIAdaptor): """ Adaptor class for server glue to Sanic framework. @@ -33,13 +34,18 @@ class ParamWrapper(api_impl.ASGIAdaptor): return cast(Optional[str], self.request.headers.get(name, default)) - def error(self, msg: str) -> SanicException: - return SanicException(msg, status_code=400) + def error(self, msg: str, status: int = 400) -> SanicException: + exception = SanicException(msg, status_code=status) + return exception - def create_response(self, status: int, output: str, - content_type: str) -> HTTPResponse: - return TextResponse(output, status=status, content_type=content_type) + + def create_response(self, status: int, output: str) -> HTTPResponse: + return TextResponse(output, status=status, content_type=self.content_type) + + + def config(self) -> Configuration: + return cast(Configuration, self.request.app.ctx.api.config) def _wrap_endpoint(func: api_impl.EndpointFunc)\