This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/document-authoring/troubleshooting/error-handling.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Error handling

Document Authoring validates structured fragments before it inserts or loads them. If a fragment is invalid, Document Authoring throws a typed DocAuthError. This can happen when you insert a fragment with insertContentAtCursor() or load a fragment you saved earlier.

Use the DocAuthError type guards to distinguish fragment validation errors from other runtime errors. Then handle each case.

Before you start, make sure the Document Authoring library is installed and running in your app. If you haven’t set it up yet, refer to the getting started guide.

Understand fragment error types

A DocAuthError is one of three fragment errors. Each error includes a type discriminator and a human-readable message:

Catch fragment errors

Use isDocAuthError() as a catch-all guard to separate fragment validation failures from other errors. Rethrow errors that you don’t recognize:

import DocAuth from '@nutrient-sdk/document-authoring';
try {
editor.insertContentAtCursor({ format: 'fragment', content: fragment });
} catch (error) {
if (DocAuth.isDocAuthError(error)) {
console.error(`Fragment rejected: ${error.message}`);
} else {
throw error; // Not a Document Authoring error — let it propagate.
}
}

Handle a specific error

Use the per-type guards to narrow the error and read fields that belong to that error type. This example reports a version mismatch and handles the other fragment error types:

import DocAuth from '@nutrient-sdk/document-authoring';
try {
editor.insertContentAtCursor({ format: 'fragment', content: fragment });
} catch (error) {
if (DocAuth.isUnsupportedFragmentVersionError(error)) {
console.error(`Unsupported fragment version; expected ${error.expected}.`);
} else if (DocAuth.isInvalidFragmentTypeError(error)) {
console.error('The data is not a valid fragment.');
} else if (DocAuth.isMissingFragmentContentError(error)) {
console.error('The fragment is empty.');
} else if (DocAuth.isDocAuthError(error)) {
console.error(error.message);
} else {
throw error;
}
}

These typed errors only cover fragment validation. Other operations surface ordinary errors, including file import, document export, and network requests. Handle those operations with a normal try/catch.

Learn more

Refer to these guides for related fragment and document workflows: