Global settings and errors

@adk/fmdapi exports one global setting and two dedicated error classes. Most applications only need the error classes at a shared error boundary.

Legacy Web Viewer name setting

globalSettings.setWebViewerName() is retained as a no-op for apps scaffolded before ADK 0.8:

Copy
import { globalSettings } from "@adk/fmdapi";

globalSettings.setWebViewerName("web");

Older fmFetch implementations required this setting to route callback events. fmFetch now executes scripts directly via window.FileMaker.PerformScriptAsync and reads the Exit Script result directly, making this setting unnecessary for new code. See Script calls.

Handle FileMaker Data API errors

WebViewerAdapter throws FileMakerError when the FileMaker Data API engine returns a non-zero error code:

Copy
import { FileMakerError } from "@adk/fmdapi";

try {
  await ContactsLayout.find({ query: { Status: "Active" } });
} catch (error) {
  if (error instanceof FileMakerError) {
    console.error(`FileMaker error ${error.code}: ${error.message}`);
  }
}

FileMakerError

Property Type Description
name string Inherited from Error.
message string Describes the failed Data API response.
code string FileMaker numeric error code represented as a string.

The code is extracted from the first item in the Data API messages array (defaults to "500" if missing). When empty finds are expected, use maybeFindFirst() or ignoreEmptyResult: true. See Record methods and pagination.

Handle container upload timeouts

containerUpload() throws ContainerUploadTimeoutError when the upload script does not respond before the configured timeout:

Copy
import { ContainerUploadTimeoutError } from "@adk/fmdapi";

try {
  await ContactsLayout.containerUpload({
    recordId: "42",
    fieldName: "Photo",
    file,
  });
} catch (error) {
  if (error instanceof ContainerUploadTimeoutError) {
    console.warn(
      `${error.scriptName} did not respond within ${error.timeoutMs}ms`,
    );
  }
}

ContainerUploadTimeoutError

Property Type Description
name "ContainerUploadTimeoutError" Identifies this error class.
message string Names the script and configured timeout.
scriptName string FileMaker script used for the upload.
timeoutMs number Configured timeout in milliseconds.
outcome "unknown" The upload may still complete asynchronously after timing out.

Verify the target record before retrying; uploads may succeed after timeout expiration. See containerUpload() and WebViewerAdapter container settings.

Handle general errors

Errors without dedicated classes inherit from standard JavaScript Error, including:

  • Passing query limit values below 1.

  • Single-record helpers (findOne) receiving unexpected record counts.

  • Schema validation failures (also logged to console.error).

  • Invoking script calls when window.FileMaker is unavailable.

  • Invalid container upload arguments (missing extensions, unsupported repetitions, or exceeding file size limits).

  • Malformed response envelopes from FileMaker batch scripts.

Handle dedicated classes first, followed by general error handlers:

Copy
import {
  ContainerUploadTimeoutError,
  FileMakerError,
} from "@adk/fmdapi";

try {
  await runFileMakerWork();
} catch (error) {
  if (error instanceof FileMakerError) {
    handleFileMakerError(error.code, error.message);
  } else if (error instanceof ContainerUploadTimeoutError) {
    await checkWhetherUploadCompleted();
  } else if (error instanceof Error) {
    reportUnexpectedError(error);
  } else {
    reportUnexpectedError(new Error(String(error)));
  }
}