snowcell
Version:
Official Snowcell Node.js/TypeScript SDK
44 lines • 1.24 kB
JavaScript
export class SnowcellException extends Error {
}
export class SnowcellError extends SnowcellException {
type;
title;
status;
detail;
instance;
constructor(init = {}) {
super(init.message ?? 'Snowcell API Error');
this.name = 'SnowcellError';
Object.assign(this, init);
}
static async fromResponse(res) {
let data = {};
try {
data = await res.json();
}
catch {
// ignore
}
const err = new SnowcellError({
type: data?.type,
title: data?.title,
status: res.status,
detail: data?.detail,
instance: data?.instance,
});
err.message =
`Snowcell API Error\n` +
Object.entries({
type: err.type,
title: err.title,
status: err.status,
detail: err.detail,
instance: err.instance,
})
.filter(([, v]) => v !== undefined && v !== null)
.map(([k, v]) => `${k}: ${v}`)
.join('\n');
return err;
}
}
//# sourceMappingURL=errors.js.map