UNPKG

gurted

Version:

A lightweight Node.js implementation of the gurt:// protocol

40 lines (39 loc) 1.19 kB
// src/error.ts export class GurtError extends Error { constructor(message, type = 'GurtError') { super(message); this.name = type; this.type = type; } static crypto(message) { return new GurtError(message, 'CryptoError'); } static protocol(message) { return new GurtError(message, 'ProtocolError'); } static invalidMessage(message) { return new GurtError(message, 'InvalidMessageError'); } static connection(message) { return new GurtError(message, 'ConnectionError'); } static handshake(message) { return new GurtError(message, 'HandshakeError'); } static timeout(message) { return new GurtError(message, 'TimeoutError'); } static server(status, message) { const error = new GurtError(`${status} ${message}`, 'ServerError'); error.status = status; return error; } static client(message) { return new GurtError(message, 'ClientError'); } static fromError(error, type = 'GurtError') { if (error instanceof GurtError) return error; return new GurtError(error.message, type); } }