@proofkit/fmodata
Version:
FileMaker OData API client
149 lines (148 loc) • 4.56 kB
JavaScript
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 {
constructor(url, status, statusText, response) {
super(`HTTP ${status} ${statusText} for ${url}`);
__publicField(this, "kind", "HTTPError");
__publicField(this, "url");
__publicField(this, "status");
__publicField(this, "statusText");
__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 {
constructor(url, message, code, details) {
super(`OData error: ${message}`);
__publicField(this, "kind", "ODataError");
__publicField(this, "url");
__publicField(this, "code");
__publicField(this, "details");
this.url = url;
this.code = code;
this.details = details;
}
}
class SchemaLockedError extends FMODataError {
constructor(url, message, details) {
super(`OData error: ${message}`);
__publicField(this, "kind", "SchemaLockedError");
__publicField(this, "url");
__publicField(this, "code");
__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 ? { cause: options.cause } : void 0
);
__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 {
constructor(expected, received) {
super(`Invalid response structure: expected ${expected}`);
__publicField(this, "kind", "ResponseStructureError");
__publicField(this, "expected");
__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;
}
}
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 isFMODataError(error) {
return error instanceof FMODataError;
}
export {
FMODataError,
HTTPError,
InvalidLocationHeaderError,
ODataError,
RecordCountMismatchError,
ResponseStructureError,
SchemaLockedError,
ValidationError,
isFMODataError,
isHTTPError,
isODataError,
isRecordCountMismatchError,
isResponseStructureError,
isSchemaLockedError,
isValidationError
};
//# sourceMappingURL=errors.js.map