Data Access

Errors

Understand error responses and handle failures gracefully.

Understand HTTP Status Codes

Every response includes an HTTP status code indicating the result of the request.

CodeMeaning
200OK — request succeeded
204No Content — delete succeeded
400Bad Request — validation failed or malformed request
401Unauthorized — missing or invalid credentials
403Forbidden — insufficient permissions
404Not Found — item or collection does not exist
500Internal Server Error

Read the Error Response

When a request fails, the API returns a JSON body with the EngineError shape:

{
  "message": "Item not found in articles",
  "source": {
    "message": "No record matched the given key"
  },
  "meta": {
    "collection": "articles"
  }
}
FieldTypeDescription
messagestringHuman-readable error description
sourceEngineError (optional)Nested error providing deeper context. Chains recursively.
metaRecord<string, unknown> (optional)Additional structured metadata about the error

The source field chains recursively — an error can contain a source that itself has a source, providing a full error chain from the outermost context down to the root cause.


Handle Errors in REST

Check response.ok before parsing the body. On failure, parse the error body to read the message and optional source chain.

fetch
const response = await fetch('https://example.monospace.io/api/blog/items/articles?fields=*', {
  headers: {
    Authorization: 'Bearer YOUR_API_KEY',
  },
});

if (!response.ok) {
  const error = await response.json();
  console.error(`${response.status}: ${error.message}`);

  if (error.source) {
    console.error('Caused by:', error.source.message);
  }

  return;
}

const { data } = await response.json();

Handle Errors in the SDK

The SDK maps API error responses to typed error classes for structured error handling:

ClassHTTP StatusExtra Properties
MonospaceNotFoundError404.collection, .key
MonospaceValidationError400.meta
MonospaceAuthError401
MonospacePermissionError403

See Advanced — Error Handling for the complete error class reference, instanceof patterns, and source chain access.


Fix Common Errors

Use this table to diagnose the most frequent error scenarios.

StatusContextLikely Cause
401Any requestAPI key is missing, expired, or malformed
403List itemsRole lacks read permission on the collection
403Get single itemNo access to the specific item, or the item does not exist
404Any requestCollection or endpoint does not exist
400Create or updateRequired field missing, or a validation rule failed
A 403 on a single-item request does not distinguish between "no access" and "does not exist." This is intentional — exposing whether an item exists would be a security risk.

See Also

Copyright © 2026