dot-lookup: fix 'Failed to fetch' caused by SOS timeout exceeding nginx proxy limit
Two WORKER_URL/entity-status calls both had 20s timeouts; worst case 40s total response time exceeds nginx proxy_read_timeout, dropping the connection and causing the browser to show 'Failed to fetch'. Also wraps fmcsaFetch calls explicitly so FMCSA API failure still returns full local census data. - AbortSignal.timeout(20000) -> 5000 on both SOS entity-status calls - fmcsaFetch carrier + authority calls wrapped in individual try/catch Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0b7a35a58e
commit
e0be6468d4
1 changed files with 18 additions and 8 deletions
|
|
@ -66,13 +66,23 @@ router.get("/api/v1/dot/lookup", async (req, res) => {
|
||||||
);
|
);
|
||||||
const census = local.rows[0] || null;
|
const census = local.rows[0] || null;
|
||||||
|
|
||||||
// 2. Live FMCSA API
|
// 2. Live FMCSA API — wrapped so a timeout or outage still returns census data
|
||||||
const snapshot = await fmcsaFetch(rawDot);
|
let carrier: any = null;
|
||||||
const carrier = snapshot?.content?.carrier || null;
|
try {
|
||||||
|
const snapshot = await fmcsaFetch(rawDot);
|
||||||
|
carrier = snapshot?.content?.carrier || null;
|
||||||
|
} catch {
|
||||||
|
// FMCSA live API unavailable — continue with local census data
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Authority check
|
// 3. Authority check — also non-fatal
|
||||||
const authorityData = await fmcsaFetch(`${rawDot}/authority`);
|
let authorities: any[] = [];
|
||||||
const authorities = (authorityData?.content || []).map((a: any) => a.carrierAuthority);
|
try {
|
||||||
|
const authorityData = await fmcsaFetch(`${rawDot}/authority`);
|
||||||
|
authorities = (authorityData?.content || []).map((a: any) => a.carrierAuthority);
|
||||||
|
} catch {
|
||||||
|
// Authority lookup failed — skip, checks will use census data where possible
|
||||||
|
}
|
||||||
|
|
||||||
if (!census && !carrier) {
|
if (!census && !carrier) {
|
||||||
res.status(404).json({ error: `DOT# ${rawDot} not found.` });
|
res.status(404).json({ error: `DOT# ${rawDot} not found.` });
|
||||||
|
|
@ -483,7 +493,7 @@ router.get("/api/v1/dot/lookup", async (req, res) => {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ entity_name: name, state_code: state }),
|
body: JSON.stringify({ entity_name: name, state_code: state }),
|
||||||
signal: AbortSignal.timeout(20000),
|
signal: AbortSignal.timeout(5000),
|
||||||
});
|
});
|
||||||
if (sosResp.ok) {
|
if (sosResp.ok) {
|
||||||
sosStatus = (await sosResp.json()) as { found?: boolean; status?: string; error?: string };
|
sosStatus = (await sosResp.json()) as { found?: boolean; status?: string; error?: string };
|
||||||
|
|
@ -688,7 +698,7 @@ router.post("/api/v1/dot/name-check", async (req, res) => {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ entity_name: name, state_code: stateCode }),
|
body: JSON.stringify({ entity_name: name, state_code: stateCode }),
|
||||||
signal: AbortSignal.timeout(20000),
|
signal: AbortSignal.timeout(5000),
|
||||||
}).then(r => r.json())
|
}).then(r => r.json())
|
||||||
: Promise.resolve({ skipped: true }),
|
: Promise.resolve({ skipped: true }),
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue