QHR Developers

Errors

When a request fails, QHR answers with an HTTP status code and a JSON body that always has the same two fields:

json
{ "error": "Token expired", "code": "token_expired" }
  • code is a stable, machine-readable identifier. Branch on code in your code. It never changes and is never translated.
  • error is a human-readable message in the language you asked for with Accept-Language. Show it to people, log it, but don't parse it. Its wording can change at any time.

Some errors add more fields:

  • errors on 422 validation_failed maps each invalid field to its messages:

    json
    {
      "error": "Validation failed",
      "code": "validation_failed",
      "errors": { "email": ["is invalid"], "start_date": ["can't be blank"] }
    }
    
  • reason on entitlement_blocked says why a feature is unavailable: not_released, not_in_plan or not_enabled.

Error catalogue

These codes can come from any endpoint.

HTTPcodeWhat it meansHow to fix it
401token_missingThere is no Authorization: Bearer … header, or it is malformed.Send Authorization: Bearer qhr_… with the full token.
401token_invalidThe 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.
401token_expiredThe token is past its expiry date.Create a new token and replace the old one.
401token_revokedThe token was revoked by its owner or an administrator.Create a new token, or ask your administrator why it was revoked.
401tenant_inactiveThe company account is suspended.Contact QHR support.
403tenant_access_revokedThe token's owner is no longer a member of the company.The owner must be invited back, then create a new token.
403employee_inactiveThe owner's employee record is not active.Ask HR to reactivate the employee record.
403token_read_onlyA read-only token tried to change data.Use a token created with Allow changes.
403forbiddenThe owner's role doesn't have the permission this operation needs.Ask an administrator for the permission shown on the endpoint's page.
425entitlement_blocked (reason: not_released)The feature behind this endpoint hasn't launched yet.Wait for the launch.
402entitlement_blocked (reason: not_in_plan)This feature isn't available for your company.Contact your QHR account manager.
412entitlement_blocked (reason: not_enabled)The feature is switched off for your company.An administrator must switch it on.
400bad_requestParameters are missing or malformed.Check the parameters against the endpoint's page.
404not_foundThe record doesn't exist, or you aren't allowed to see it.Check the id. List the records first to get a valid one.
422validation_failedThe data broke a business rule. Details are in errors.Fix the fields listed in errors and try again.
422operation-specificA 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.
429rate_limitedToo many requests.Wait the number of seconds in the Retry-After header, then retry. See Rate limits.
500internal_errorSomething 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. 4xx means the request needs to change; 5xx and 429 mean the same request may succeed later.
  • Retry only what is retryable. Retry 429 after Retry-After, and 500, 502, 503, 504 with exponential backoff (for example 1 s, 2 s, 4 s, at most 5 tries). Never blindly retry 4xx errors other than 429.
  • Be careful retrying writes. If a POST times out, the change may already have happened. Read the data back before you send it again.
  • Show error to people. It is already translated, so you can display it as is.
  • Log code and the time. Support can find a failed request from the time and your token's public id. Never log the token itself.
js
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}`);
  }
}