{"version":3,"file":"error.cjs","names":[],"sources":["../src/error.ts"],"sourcesContent":["/**\n * Common shape of error bodies returned by the Storyblok Management API.\n *\n * Most error responses include an `error` field with a human-readable message.\n */\nexport interface ApiErrorBody {\n  error?: string;\n  message?: string;\n  [key: string]: unknown;\n}\n\n/**\n * Structured error surfaced by the Management API client for a failed request.\n *\n * For an HTTP error response, it's thrown when `throwOnError: true` and otherwise\n * returned as `result.error`. A transport failure (no HTTP response at all — a timeout,\n * an abort, a DNS failure) is thrown as its original error instead when\n * `throwOnError: true`, so its identity survives; it's only wrapped here, with\n * `response.status` 0, when it resolves as `result.error`, to keep that field's type\n * accurate.\n */\nexport class ClientError extends Error {\n  readonly response: { status: number; statusText: string; data: ApiErrorBody | undefined };\n  /**\n   * The underlying error, when this `ClientError` wraps one rather than an HTTP\n   * response. Not set for ordinary HTTP error responses: their failure detail already\n   * lives in `response.data`, and `error` there is the parsed body, not a cause.\n   * `Error`'s own `cause` constructor option isn't available at this package's `lib`\n   * target, so this is declared and assigned as a plain own field instead.\n   */\n  readonly cause?: unknown;\n\n  constructor(\n    message: string,\n    options: { status: number; statusText: string; data: unknown; cause?: unknown },\n  ) {\n    super(message);\n    this.name = \"ClientError\";\n    this.cause = options.cause;\n    this.response = {\n      status: options.status,\n      statusText: options.statusText,\n      data: options.data as ApiErrorBody | undefined,\n    };\n  }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,cAAb,cAAiC,MAAM;CACrC;;;;;;;;CAQA;CAEA,YACE,SACA,SACA;EACA,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,QAAQ,QAAQ;EACrB,KAAK,WAAW;GACd,QAAQ,QAAQ;GAChB,YAAY,QAAQ;GACpB,MAAM,QAAQ;EAChB;CACF;AACF"}