mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
api: generalize error handling
Return a consistent error response which takes into account the chosen content type. Also adds tests for V1 server glue.
This commit is contained in:
@@ -46,10 +46,10 @@ class ParamWrapper(api_impl.ASGIAdaptor):
|
||||
return falcon.HTTPError(status, description=msg)
|
||||
|
||||
|
||||
def create_response(self, status: int, output: str, content_type: str) -> None:
|
||||
def create_response(self, status: int, output: str) -> None:
|
||||
self.response.status = status
|
||||
self.response.text = output
|
||||
self.response.content_type = content_type
|
||||
self.response.content_type = self.content_type
|
||||
|
||||
|
||||
def config(self) -> Configuration:
|
||||
|
||||
@@ -38,9 +38,8 @@ class ParamWrapper(api_impl.ASGIAdaptor):
|
||||
return SanicException(msg, status_code=status)
|
||||
|
||||
|
||||
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:
|
||||
|
||||
@@ -42,8 +42,8 @@ class ParamWrapper(api_impl.ASGIAdaptor):
|
||||
return HTTPException(status, detail=msg)
|
||||
|
||||
|
||||
def create_response(self, status: int, output: str, content_type: str) -> Response:
|
||||
return Response(output, status_code=status, media_type=content_type)
|
||||
def create_response(self, status: int, output: str) -> Response:
|
||||
return Response(output, status_code=status, media_type=self.content_type)
|
||||
|
||||
|
||||
def config(self) -> Configuration:
|
||||
|
||||
Reference in New Issue
Block a user