Workforce locations: include Tanda error body in 502 response

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-07 12:59:29 +00:00
parent db1b168300
commit 5a9a05bb62

View file

@ -127,7 +127,11 @@ export async function integrationRoutes(app) {
headers: { Authorization: `Bearer ${creds.bearer_token}` },
signal: AbortSignal.timeout(8000),
})
if (!res.ok) return reply.status(502).send({ error: `Workforce API error (${res.status})` })
if (!res.ok) {
const body = await res.text().catch(() => '')
const msg = (() => { try { return JSON.parse(body).error } catch { return body.slice(0, 200) } })()
return reply.status(502).send({ error: msg || `Workforce API error (${res.status})` })
}
const data = await res.json()
const items = Array.isArray(data) ? data : (data.locations ?? [])
locations.push(...items.map(l => ({ id: String(l.id), name: l.name, short_name: l.short_name ?? null })))