You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import { Response } from 'node-fetch';
|
|
|
|
export class EmptySwarmError extends Error {
|
|
public error: any;
|
|
public pubkey: string;
|
|
constructor(pubkey: string, message: string) {
|
|
// 'Error' breaks prototype chain here
|
|
super(message);
|
|
this.pubkey = pubkey.split('.')[0];
|
|
this.name = 'EmptySwarmError';
|
|
|
|
// restore prototype chain
|
|
const actualProto = new.target.prototype;
|
|
|
|
if (Object.setPrototypeOf) {
|
|
Object.setPrototypeOf(this, actualProto);
|
|
}
|
|
// Maintains proper stack trace, where our error was thrown (only available on V8)
|
|
// via https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
export class NotFoundError extends Error {
|
|
public error: any;
|
|
constructor(message: string, error: any) {
|
|
// 'Error' breaks prototype chain here
|
|
super(message);
|
|
this.error = error;
|
|
this.name = 'NotFoundError';
|
|
|
|
// restore prototype chain
|
|
const actualProto = new.target.prototype;
|
|
|
|
if (Object.setPrototypeOf) {
|
|
Object.setPrototypeOf(this, actualProto);
|
|
}
|
|
// Maintains proper stack trace, where our error was thrown (only available on V8)
|
|
// via https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
export class HTTPError extends Error {
|
|
public response: Response;
|
|
constructor(message: string, response: Response) {
|
|
// 'Error' breaks prototype chain here
|
|
super(`${response.status} Error: ${message}`);
|
|
this.response = response;
|
|
this.name = 'HTTPError';
|
|
|
|
// restore prototype chain
|
|
const actualProto = new.target.prototype;
|
|
|
|
if (Object.setPrototypeOf) {
|
|
Object.setPrototypeOf(this, actualProto);
|
|
}
|
|
// Maintains proper stack trace, where our error was thrown (only available on V8)
|
|
// via https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
class BaseError extends Error {
|
|
public readonly context?: Object;
|
|
constructor(message: string, context?: Object) {
|
|
super(message);
|
|
this.name = this.constructor.name;
|
|
this.context = context;
|
|
}
|
|
}
|
|
|
|
export class SigningFailed extends BaseError {}
|
|
export class InvalidSigningType extends BaseError {}
|
|
export class GroupV2SigningFailed extends SigningFailed {}
|
|
export class PreConditionFailed extends BaseError {}
|