Nutrient Web SDK

ReferenceNutrientViewerisPreviousDocumentClosedError

Function isPreviousDocumentClosedError

Whether a rejected NutrientViewer.Instance#load gave up after the document that was on screen had already been closed.

This answers the one question a host cannot answer by inspecting the instance: whether the document it was showing survived the failed load.

  • false — the load failed before the previous document was closed. That document is still open, rendered and interactive. The failed call can leave three traces. Pending changes were flushed first, which is the save the instance's NutrientViewer.AutoSaveMode had already promised. A print job or a search that was running may have been cancelled. And an open content editor may have been closed without saving its edits. The last two happen when the load failed while it was about to replace the document.
  • true — the previous document had already been closed when the failure happened, so the viewer has no open document and shows its error state instead. A later successful load() recovers it. This also covers a load() that fails while the viewer still shows the error state of an earlier failed load().

The check follows the error's cause chain, so it still holds for an error the SDK wrapped to give it a better message.

Treat true as a temporary floor rather than a guarantee that this state is reachable. It happens for a document that goes to OPFS storage, which is only opened after the previous document was closed, and for a failure that follows a successful open. If a future version removes one of these cases, this predicate simply stops returning true for it, which is not a breaking change for a host that branches on it.

Function
Type Signature
isPreviousDocumentClosedError(error: unknown): boolean
  • Type Declaration

    Parameters

    errorunknown

    The value a rejected NutrientViewer.Instance#load threw.

    Returns

    boolean

    true when the viewer has no open document after this failure.

    Example

    try {
    await instance.load({ document: "/b.pdf" });
    } catch (error) {
    if (NutrientViewer.isPreviousDocumentClosedError(error)) {
    // Nothing is on screen anymore — offer a retry or load a known-good document.
    }
    }