UNPKG

@proofkit/fmodata

Version:

FileMaker OData API client

241 lines (240 loc) 8.39 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); class FMODataError extends Error { constructor(message, options) { super(message, options); __publicField(this, "timestamp"); this.name = this.constructor.name; this.timestamp = /* @__PURE__ */ new Date(); } } class HTTPError extends FMODataError { // biome-ignore lint/suspicious/noExplicitAny: Dynamic response type from OData API constructor(url, status, statusText, response) { super(`HTTP ${status} ${statusText} for ${url}`); __publicField(this, "kind", "HTTPError"); __publicField(this, "url"); __publicField(this, "status"); __publicField(this, "statusText"); // biome-ignore lint/suspicious/noExplicitAny: Dynamic response type from OData API __publicField(this, "response"); this.url = url; this.status = status; this.statusText = statusText; this.response = response; } // Helper methods for common status checks is4xx() { return this.status >= 400 && this.status < 500; } is5xx() { return this.status >= 500 && this.status < 600; } isNotFound() { return this.status === 404; } isUnauthorized() { return this.status === 401; } isForbidden() { return this.status === 403; } } class ODataError extends FMODataError { // biome-ignore lint/suspicious/noExplicitAny: Dynamic error details from OData API constructor(url, message, code, details) { super(`OData error: ${message}`); __publicField(this, "kind", "ODataError"); __publicField(this, "url"); __publicField(this, "code"); // biome-ignore lint/suspicious/noExplicitAny: Dynamic error details from OData API __publicField(this, "details"); this.url = url; this.code = code; this.details = details; } } class SchemaLockedError extends FMODataError { // biome-ignore lint/suspicious/noExplicitAny: Dynamic error details from OData API constructor(url, message, details) { super(`OData error: ${message}`); __publicField(this, "kind", "SchemaLockedError"); __publicField(this, "url"); __publicField(this, "code"); // biome-ignore lint/suspicious/noExplicitAny: Dynamic error details from OData API __publicField(this, "details"); this.url = url; this.code = "303"; this.details = details; } } class ValidationError extends FMODataError { constructor(message, issues, options) { super(message, (options == null ? void 0 : options.cause) === void 0 ? void 0 : { cause: options.cause }); __publicField(this, "kind", "ValidationError"); __publicField(this, "field"); __publicField(this, "issues"); __publicField(this, "value"); this.field = options == null ? void 0 : options.field; this.issues = issues; this.value = options == null ? void 0 : options.value; } } class ResponseStructureError extends FMODataError { // biome-ignore lint/suspicious/noExplicitAny: Dynamic response type from OData API constructor(expected, received) { super(`Invalid response structure: expected ${expected}`); __publicField(this, "kind", "ResponseStructureError"); __publicField(this, "expected"); // biome-ignore lint/suspicious/noExplicitAny: Dynamic response type from OData API __publicField(this, "received"); this.expected = expected; this.received = received; } } class RecordCountMismatchError extends FMODataError { constructor(expected, received) { const expectedStr = typeof expected === "number" ? expected : expected; super(`Expected ${expectedStr} record(s), but received ${received}`); __publicField(this, "kind", "RecordCountMismatchError"); __publicField(this, "expected"); __publicField(this, "received"); this.expected = expected; this.received = received; } } class InvalidLocationHeaderError extends FMODataError { constructor(message, locationHeader) { super(message); __publicField(this, "kind", "InvalidLocationHeaderError"); __publicField(this, "locationHeader"); this.locationHeader = locationHeader; } } class ResponseParseError extends FMODataError { constructor(url, message, options) { super(message, (options == null ? void 0 : options.cause) ? { cause: options.cause } : void 0); __publicField(this, "kind", "ResponseParseError"); __publicField(this, "url"); __publicField(this, "rawText"); this.url = url; this.rawText = options == null ? void 0 : options.rawText; } } class BatchTruncatedError extends FMODataError { constructor(operationIndex, failedAtIndex) { super(`Operation ${operationIndex} was not executed because operation ${failedAtIndex} failed`); __publicField(this, "kind", "BatchTruncatedError"); __publicField(this, "operationIndex"); __publicField(this, "failedAtIndex"); this.operationIndex = operationIndex; this.failedAtIndex = failedAtIndex; } } class MissingLayerServiceError extends FMODataError { constructor(service, options) { super( `Required layer service "${service}" is not available`, (options == null ? void 0 : options.cause) ? { cause: options.cause } : void 0 ); __publicField(this, "kind", "MissingLayerServiceError"); __publicField(this, "service"); this.service = service; } } class MetadataNotFoundError extends FMODataError { constructor(databaseName) { super(`Metadata for database "${databaseName}" not found in response`); __publicField(this, "kind", "MetadataNotFoundError"); __publicField(this, "databaseName"); this.databaseName = databaseName; } } class BuilderInvariantError extends FMODataError { constructor(builder, message, options) { super(`${builder} invariant violation: ${message}`, (options == null ? void 0 : options.cause) ? { cause: options.cause } : void 0); __publicField(this, "kind", "BuilderInvariantError"); __publicField(this, "builder"); this.builder = builder; } } class SchemaValidationFailedError extends FMODataError { constructor(operation, message, options) { super(`${operation} schema validation failed: ${message}`, (options == null ? void 0 : options.cause) ? { cause: options.cause } : void 0); __publicField(this, "kind", "SchemaValidationFailedError"); __publicField(this, "operation"); __publicField(this, "issues"); this.operation = operation; this.issues = options == null ? void 0 : options.issues; } } function isHTTPError(error) { return error instanceof HTTPError; } function isValidationError(error) { return error instanceof ValidationError; } function isODataError(error) { return error instanceof ODataError; } function isSchemaLockedError(error) { return error instanceof SchemaLockedError; } function isResponseStructureError(error) { return error instanceof ResponseStructureError; } function isRecordCountMismatchError(error) { return error instanceof RecordCountMismatchError; } function isResponseParseError(error) { return error instanceof ResponseParseError; } function isBatchTruncatedError(error) { return error instanceof BatchTruncatedError; } function isFMODataError(error) { return error instanceof FMODataError; } function isTransientError(error) { if (error instanceof SchemaLockedError) { return true; } if (error && typeof error === "object") { const name = Reflect.get(error, "name"); if (typeof name === "string" && (name === "NetworkError" || name === "TimeoutError")) { return true; } } if (error instanceof HTTPError && error.is5xx()) { return true; } return false; } export { BatchTruncatedError, BuilderInvariantError, FMODataError, HTTPError, InvalidLocationHeaderError, MetadataNotFoundError, MissingLayerServiceError, ODataError, RecordCountMismatchError, ResponseParseError, ResponseStructureError, SchemaLockedError, SchemaValidationFailedError, ValidationError, isBatchTruncatedError, isFMODataError, isHTTPError, isODataError, isRecordCountMismatchError, isResponseParseError, isResponseStructureError, isSchemaLockedError, isTransientError, isValidationError }; //# sourceMappingURL=errors.js.map