Errors
When a request fails, QHR answers with an HTTP status code and a JSON body that always has the same two fields:
{ "error": "Token expired", "code": "token_expired" }
codeis a stable, machine-readable identifier. Branch oncodein your code. It never changes and is never translated.erroris a human-readable message in the language you asked for withAccept-Language. Show it to people, log it, but don't parse it. Its wording can change at any time.
Some errors add more fields:
-
errorson422 validation_failedmaps each invalid field to its messages:json{ "error": "Validation failed", "code": "validation_failed", "errors": { "email": ["is invalid"], "start_date": ["can't be blank"] } } -
reasononentitlement_blockedsays why a feature is unavailable:not_released,not_in_planornot_enabled.
Error catalogue
These codes can come from any endpoint.
| HTTP | code | What it means | How to fix it |
|---|---|---|---|
| 401 | token_missing | There is no Authorization: Bearer … header, or it is malformed. | Send Authorization: Bearer qhr_… with the full token. |
| 401 | token_invalid | The token is unknown or wrong, or its owner's account is locked. | Check that the token was copied completely. If it still fails, create a new one in Settings › API & Integrations. |
| 401 | token_expired | The token is past its expiry date. | Create a new token and replace the old one. |
| 401 | token_revoked | The token was revoked by its owner or an administrator. | Create a new token, or ask your administrator why it was revoked. |
| 401 | tenant_inactive | The company account is suspended. | Contact QHR support. |
| 403 | tenant_access_revoked | The token's owner is no longer a member of the company. | The owner must be invited back, then create a new token. |
| 403 | employee_inactive | The owner's employee record is not active. | Ask HR to reactivate the employee record. |
| 403 | token_read_only | A read-only token tried to change data. | Use a token created with Allow changes. |
| 403 | forbidden | The owner's role doesn't have the permission this operation needs. | Ask an administrator for the permission shown on the endpoint's page. |
| 425 | entitlement_blocked (reason: not_released) | The feature behind this endpoint hasn't launched yet. | Wait for the launch. |
| 402 | entitlement_blocked (reason: not_in_plan) | This feature isn't available for your company. | Contact your QHR account manager. |
| 412 | entitlement_blocked (reason: not_enabled) | The feature is switched off for your company. | An administrator must switch it on. |
| 400 | bad_request | Parameters are missing or malformed. | Check the parameters against the endpoint's page. |
| 404 | not_found | The record doesn't exist, or you aren't allowed to see it. | Check the id. List the records first to get a valid one. |
| 422 | validation_failed | The data broke a business rule. Details are in errors. | Fix the fields listed in errors and try again. |
| 422 | operation-specific | A rule specific to one operation, for example insufficient_balance when requesting leave. | See that endpoint's page: each one lists its own codes and fixes. |
| 429 | rate_limited | Too many requests. | Wait the number of seconds in the Retry-After header, then retry. See Rate limits. |
| 500 | internal_error | Something went wrong on QHR's side. | Retry a little later. If it keeps happening, contact support with the time of the request. |
Each endpoint page has its own errors table with the codes that endpoint can return, including its operation-specific ones.
404 can mean "not yours"
404 not_found covers both "this record doesn't exist" and "this record exists but you aren't allowed to see it". QHR doesn't tell the two apart, so it never reveals which ids exist. If you're sure an id is right, check that the token's owner can open that record in the web app.
Handling errors well
- Check the status first, then
code.4xxmeans the request needs to change;5xxand429mean the same request may succeed later. - Retry only what is retryable. Retry
429afterRetry-After, and500,502,503,504with exponential backoff (for example 1 s, 2 s, 4 s, at most 5 tries). Never blindly retry4xxerrors other than429. - Be careful retrying writes. If a
POSTtimes out, the change may already have happened. Read the data back before you send it again. - Show
errorto people. It is already translated, so you can display it as is. - Log
codeand the time. Support can find a failed request from the time and your token's public id. Never log the token itself.
const res = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
if (!res.ok) {
const body = await res.json().catch(() => ({}));
switch (body.code) {
case "token_expired":
case "token_revoked":
return alertAdmin("The QHR token needs replacing");
case "rate_limited":
return retryAfter(Number(res.headers.get("Retry-After") || 60));
case "validation_failed":
return showFieldErrors(body.errors);
default:
throw new Error(`${res.status} ${body.code}: ${body.error}`);
}
}