Errors

Every non-2xx response is an RFC 9457 problem+json document.

When a request fails, the API returns a standard RFC 9457 application/problem+json body — never an HTML page or an unstructured string:

1{
2 "type": "https://docs.usglobalmail.com/api/problems/validation_error",
3 "title": "Your request parameters did not validate.",
4 "status": 422,
5 "code": "validation_error",
6 "request_id": "req_8f3c2a1b9d",
7 "instance": "/v1/mails",
8 "detail": "is_read must be a boolean.",
9 "errors": [
10 { "field": "is_read", "message": "must be a boolean" }
11 ]
12}

The type is a dereferenceable URL — open it for a full explanation of that problem. Browse them all under Problem types.

FieldMeaning
typeA URI identifying the problem type (links into this documentation).
titleA short, human-readable summary of the problem type.
statusThe HTTP status code, repeated for convenience.
detailA human-readable explanation specific to this occurrence.
codeA stable, machine-readable string to branch on. Prefer this over title.
request_idQuote this when contacting support — it pins the exact request in our logs.
errorsPresent on 422 — the list of per-field validation failures.

Status codes

StatuscodeWhen
400bad_requestMalformed request the schema can’t accept.
401unauthorizedMissing, malformed, or invalid API key.
403forbiddenAuthenticated, but not allowed to perform this action.
404not_foundNo such resource (or not visible to this key).
405method_not_allowedThe HTTP method isn’t allowed on this endpoint.
409conflictThe request conflicts with the resource’s current state.
415unsupported_media_typeThe request Content-Type isn’t supported.
422validation_errorWell-formed request, but a field failed validation.
429rate_limitedToo many requests — see Rate limits.
500internal_errorSomething failed on our side — check System status, then retry with backoff.
502bad_gatewayAn upstream service returned an invalid response.
503service_unavailableTemporarily unavailable — retry after a short delay.
504gateway_timeoutAn upstream service timed out.

Each code links to a page with common causes, resolution steps, and an example body. Browse them all under Problem types.

Handling errors

Branch on the machine-readable code, not the human-readable title (titles may be reworded):

1import { UsgmError } from "@usgm/sdk";
2
3try {
4 await usgm.mails.get("80421");
5} catch (err) {
6 if (err instanceof UsgmError && err.code === "not_found") {
7 // handle a missing mail item
8 }
9 throw err;
10}

Always log the request_id from failed responses. It’s the fastest way for USGM support to trace what happened.