Skip to content

Explain your API's errors

Your API's errors need two things: a code a program can act on, and an explanation a person, or an AI agent, can follow. Keep the explanations in ObjectsGrid: a DefinedTermSet per API, and a DefinedTerm per code. Your product and support teams edit them without a deploy, in every language you support, and every change is a version. ObjectsGrid's own errors are described the same way, in Error details.

The catalog

curl -X POST https://apis.objectsgrid.com/definedtermsets \
  -H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"name": [{"at_language": "en", "at_value": "Orders API errors"}], "domain": "example.com",
       "mainEntityOfPage": "https://docs.example.com/errors/"}'

domain is yours: your API returns it with each code, and a code is unique within its domain, as objectsgrid.com is for ObjectsGrid's own codes.

A code

A DefinedTerm's id is the code, chosen by you, so a lookup is a plain read:

curl -X POST https://apis.objectsgrid.com/definedterms \
  -H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"id": "ORDER_LOCKED", "inDefinedTermSet": {"at_id": "https://apis.objectsgrid.com/definedtermsets/<set>"},
       "name": [{"at_language": "en", "at_value": "The order is locked"},
                {"at_language": "de", "at_value": "Die Bestellung ist gesperrt"}],
       "description": [{"at_language": "en", "at_value": "A shipped order can't change."}],
       "causes": [{"at_language": "en", "at_value": "The order shipped"},
                  {"at_language": "en", "at_value": "The order was cancelled"}],
       "remedy": [{"at_language": "en", "at_value": "Create a return instead."}],
       "httpStatus": 409,
       "seeAlso": ["https://docs.example.com/returns"],
       "internalNotes": [{"at_language": "en", "at_value": "Check the warehouse system for a stuck shipment."}],
       "mainEntityOfPage": "https://docs.example.com/errors/ORDER_LOCKED"}'
  • termCode repeats the id; ids are 1 to 50 letters, digits, - and _, and one is used once in an Organization Account, even after a delete.
  • causes holds one entry per cause and language.
  • internalNotes are for your support team. The default policy of a new Organization Account hides them from anonymous callers.

In your API's errors

Your API answers with the code and the page, in RFC 9457 form or your own:

{"type": "https://docs.example.com/errors/ORDER_LOCKED", "code": "ORDER_LOCKED", "domain": "example.com",
 "title": "The order is locked", "instance": "<your request id>"}

ObjectsGrid isn't in that request's path: your error responses never depend on it. A link carries a code and your own request id, never the data of the failed request, so the catalog holds no personal data and is safe to publish.

Your pages

The page at type is yours, rendered from the entry:

  • At build or on your server: list the set's terms once, GET /definedterms?where={"inDefinedTermSet": {"at_id": {"equals": "<set at_id>"}}}, render the pages, and rebuild on the DefinedTermUpdated webhook, or poll a term with If-None-Match: a 304 isn't billed.
  • From the browser: tag the set and the terms you publish with visibility = public, and read them with a public API key: GET /definedterms/ORDER_LOCKED?lang=de.
  • For agents: the JSON, or the term's JSON-LD document in your page, is the machine-readable explanation. GraphQL reads a set with its terms: definedTermSet(id) { hasDefinedTerm { items { termCode name { at_value } } } }.

A DefinedTermSet is any set of coded terms, so the same objects hold a glossary or a list of product codes too.