+import nominatim.api.v1 as api_impl
+import nominatim.api.logging as loglib
+from nominatim.config import Configuration
+
+class HTTPNominatimError(Exception):
+ """ A special exception class for errors raised during processing.
+ """
+ def __init__(self, msg: str, status: int, content_type: str) -> None:
+ self.msg = msg
+ self.status = status
+ self.content_type = content_type
+
+
+async def nominatim_error_handler(req: Request, resp: Response, #pylint: disable=unused-argument
+ exception: HTTPNominatimError,
+ _: Any) -> None:
+ """ Special error handler that passes message and content type as
+ per exception info.
+ """
+ resp.status = exception.status
+ resp.text = exception.msg
+ resp.content_type = exception.content_type
+
+
+async def timeout_error_handler(req: Request, resp: Response, #pylint: disable=unused-argument
+ exception: TimeoutError, #pylint: disable=unused-argument
+ _: Any) -> None:
+ """ Special error handler that passes message and content type as
+ per exception info.
+ """
+ resp.status = 503
+
+ loglib.log().comment('Aborted: Query took too long to process.')
+ logdata = loglib.get_and_disable()
+ if logdata:
+ resp.text = logdata
+ resp.content_type = 'text/html; charset=utf-8'
+ else:
+ resp.text = "Query took too long to process."
+ resp.content_type = 'text/plain; charset=utf-8'