Skip to content

Commit 76eadc5

Browse files
committed
print any collected debug output when returning a timeout error
1 parent 3cc3e3b commit 76eadc5

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

nominatim/server/falcon/server.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from nominatim.api import NominatimAPIAsync
1818
import nominatim.api.v1 as api_impl
19+
import nominatim.api.logging as loglib
1920
from nominatim.config import Configuration
2021

2122
class HTTPNominatimError(Exception):
@@ -45,8 +46,15 @@ async def timeout_error_handler(req: Request, resp: Response, #pylint: disable=u
4546
per exception info.
4647
"""
4748
resp.status = 503
48-
resp.text = "Query took too long to process."
49-
resp.content_type = 'text/plain; charset=utf-8'
49+
50+
loglib.log().comment('Aborted: Query took too long to process.')
51+
logdata = loglib.get_and_disable()
52+
if logdata:
53+
resp.text = logdata
54+
resp.content_type = 'text/html; charset=utf-8'
55+
else:
56+
resp.text = "Query took too long to process."
57+
resp.content_type = 'text/plain; charset=utf-8'
5058

5159

5260
class ParamWrapper(api_impl.ASGIAdaptor):

nominatim/server/starlette/server.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
from starlette.applications import Starlette
1616
from starlette.routing import Route
1717
from starlette.exceptions import HTTPException
18-
from starlette.responses import Response, PlainTextResponse
18+
from starlette.responses import Response, PlainTextResponse, HTMLResponse
1919
from starlette.requests import Request
2020
from starlette.middleware import Middleware
2121
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
2222
from starlette.middleware.cors import CORSMiddleware
2323

2424
from nominatim.api import NominatimAPIAsync
2525
import nominatim.api.v1 as api_impl
26+
import nominatim.api.logging as loglib
2627
from nominatim.config import Configuration
2728

2829
class ParamWrapper(api_impl.ASGIAdaptor):
@@ -115,6 +116,12 @@ async def timeout_error(request: Request, #pylint: disable=unused-argument
115116
_: Exception) -> Response:
116117
""" Error handler for query timeouts.
117118
"""
119+
loglib.log().comment('Aborted: Query took too long to process.')
120+
logdata = loglib.get_and_disable()
121+
122+
if logdata:
123+
return HTMLResponse(logdata)
124+
118125
return PlainTextResponse("Query took too long to process.", status_code=503)
119126

120127

0 commit comments

Comments
 (0)