mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
fix(routes): report an upstream routing outage as unavailable
When the OSRM routing service failed (a 5xx, a 403 block, a 404), answered
with a body that was not JSON, or did not answer at all (timeout, network
error), /api/route returned HTTP 200 with 'no route found' or 'route proxy
error'. plan_route turned that into invalid_arguments ("No walk route from
...: no route found"), blaming the caller for an outage, and the directions
layer reported "No route found between A and B".
The proxy now answers all of these with 502 {ok:false, error:'routing
service unavailable'}: a rejected upstream fetch, any failure status but
400, a non-JSON content type, and a body read that fails or does not parse.
An exception in the proxy's own code after that point is still a 200 'route
proxy error'. createRouteService throws for a 5xx before reading the body's
ok:false, so plan_route reports unavailable, and the directions source
treats any 5xx as "Routing unavailable (HTTP n)", also when the failure
page in front of the proxy is not JSON. OSRM's own refusal (a 400 such as
NoRoute, or a 200 without a route) still reads "no route found".
The 12 s upstream timeout now starts when the request leaves rather than
before it waits for an outbound slot, so a wait in the proxy's own queue
(up to about 8 s at the 1 s spacing) is not reported as an outage.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
ebd8439868
commit
f8795ff426
7 files changed
+223
-34
No files matched your search
@@ -21,7 +21,13 @@ export function createDirectionsSource({
|
||||
signal,
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
const payload = await response.json();
|
||||
// A failure page in front of the proxy need not be JSON.
|
||||
let payload = null;
|
||||
try {
|
||||
payload = await response.json();
|
||||
} catch (error) {
|
||||
if (response.ok) throw error;
|
||||
}
|
||||
signal?.throwIfAborted();
|
||||
// Failures keep their English message and carry the HTTP status and the
|
||||
// server's refusal text, so the layer can show them in the language.
|
||||
@@ -39,7 +45,9 @@ export function createDirectionsSource({
|
||||
{ status: 429, refusal },
|
||||
);
|
||||
}
|
||||
if (!response.ok && !payload?.error)
|
||||
// A 5xx is a routing outage whatever its body says; only the proxy's
|
||||
// refusals carry an error text worth showing.
|
||||
if (response.status >= 500 || (!response.ok && !payload?.error))
|
||||
throw Object.assign(
|
||||
new Error(`Routing unavailable (HTTP ${response.status})`),
|
||||
{ status: response.status },
|
||||
|
||||
@@ -41,3 +41,15 @@ test('route failures are surfaced without fallback requests', async () => {
|
||||
assert.equal(calls, 1);
|
||||
}
|
||||
});
|
||||
|
||||
test('a routing outage stays an outage when its body carries an error', async () => {
|
||||
const source = createDirectionsSource({ fetchImpl: async () =>
|
||||
Response.json({ ok: false, error: 'routing service unavailable' }, { status: 502 }) });
|
||||
await assert.rejects(source.getRoute(query), { status: 502, message: 'Routing unavailable (HTTP 502)' });
|
||||
});
|
||||
|
||||
test('a routing outage page that is not JSON still reads as an outage', async () => {
|
||||
const source = createDirectionsSource({ fetchImpl: async () =>
|
||||
new Response('<html>Bad Gateway</html>', { status: 502, headers: { 'content-type': 'text/html' } }) });
|
||||
await assert.rejects(source.getRoute(query), { status: 502, message: 'Routing unavailable (HTTP 502)' });
|
||||
});
|
||||
Reference in new issue
Block a user