hcengineering/platform · error
Request failed
Error message
Request failed
What it means
Generic fallback thrown by sendRequest when the server returned a non-OK status but no structured `error` field could be extracted from the response body (JSON parsing failed or `error` was absent), and no `options.errorMessage` override was supplied. It means the request failed at the HTTP level but the client could not determine a more specific reason.
Source
Thrown at packages/kvs-client/src/client.ts:153
if (options.returnNullOn404 === true && response.status === 404) {
return null
}
if (options.acceptNotFound === true && response.status === 404) {
return null
}
if (!response.ok) {
try {
const errorBody = await response.json()
if (errorBody?.error != null) {
throw new PlatformError(errorBody?.error)
}
} catch (e) {
// Ignore JSON parsing errors
}
throw new Error(options.errorMessage ?? 'Request failed')
}
// Parse JSON response when needed
const contentType = response.headers.get('content-type')
if (
response.status !== 204 &&
(options.method === 'GET' || (contentType != null && contentType.includes('application/json')))
) {
return await response.json()
}
return null
}
private async fetchWithRetry (url: string, init: RequestInit): Promise<Response> {
const timeout = Date.now() + this.retryTimeoutMs
const connectionErrorCodes = ['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND']
let intervalMs = 25View on GitHub (pinned to 63e28dc964)
Solutions
- Check the actual HTTP status/network traffic (browser devtools, service logs) to find the real cause.
- Confirm the baseUrl points at the correct key-value API endpoint and is reachable.
- Pass `options.errorMessage` in the request options to get a more descriptive error for your call site.
- Retry with backoff if the failure is transient (5xx/gateway errors).
Example fix
// before
await client.getValue('user:42')
// after
await client.getValue('user:42', { errorMessage: 'Failed to load user preference' }) Defensive patterns
Strategy: retry
Validate before calling
try {
const health = await fetch(baseUrl + '/health')
if (!health.ok) throw new Error('KVS service unhealthy before request')
} catch { /* service unreachable — fail early */ } Type guard
null
Try / catch
try {
await client.setValue(key, value, { errorMessage: 'Failed to save setting' })
} catch (e) {
if (e.message === 'Failed to save setting') {
// generic HTTP failure — check status/service health, consider retry
} else throw e
} Prevention
- Pass options.errorMessage on important calls to make fallback errors descriptive.
- Monitor the KVS service health and alert on 5xx spikes.
- Use retries with exponential backoff for idempotent operations.
- Check gateway/proxy config if HTML error pages appear in logs.
When it happens
Trigger: setValue/getValue/deleteKey/listKeys receiving an HTTP error response (4xx/5xx) with a non-JSON body, an empty body, or JSON lacking an `error` field.
Common situations: A gateway/proxy returning HTML error pages (502/504), the service being down or restarting, a wrong URL hitting a different server that doesn't return the expected error shape, or CORS intercepting the response body in browsers.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- ${errorBody?.error}
- ${error.error ?? text}
- Payment service error: ${response.status} ${text}
- err.message?.length > 0 ? err.message : 'Internal Server Err
- Export failed
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/2be535e4f2c38b33.
Report an issue: GitHub.