UNPKG

@instantdb/core

Version:
37 lines 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InstantAPIError = void 0; exports.jsonFetch = jsonFetch; const InstantError_ts_1 = require("../InstantError.js"); class InstantAPIError extends InstantError_ts_1.InstantError { body; status; constructor(error) { // Create a descriptive message based on the error const message = error.body?.message || `API Error (${error.status})`; super(message, error.body.hint, error.body['trace-id']); const actualProto = new.target.prototype; if (Object.setPrototypeOf) { Object.setPrototypeOf(this, actualProto); } // Maintain proper stack trace for where our error was thrown if (Error.captureStackTrace) { Error.captureStackTrace(this, InstantAPIError); } this.name = 'InstantAPIError'; this.status = error.status; this.body = error.body; } get [Symbol.toStringTag]() { return 'InstantAPIError'; } } exports.InstantAPIError = InstantAPIError; async function jsonFetch(input, init) { const res = await fetch(input, init); const json = await res.json(); return res.status === 200 ? Promise.resolve(json) : Promise.reject(new InstantAPIError({ status: res.status, body: json })); } //# sourceMappingURL=fetch.js.map