UNPKG

@instantdb/core

Version:
32 lines 1.15 kB
import { InstantError } from "../InstantError.js"; export class InstantAPIError extends 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); 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'; } } export 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