@n1k1t/mock-server
Version:
The ultimate toolkit to intercept, transform, and simulate HTTP/WS traffic with type-safe expectations
32 lines • 1.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebSocketConnectionError = void 0;
const url_1 = __importDefault(require("url"));
class WebSocketConnectionError extends Error {
constructor(ws, reason) {
const { protocol, host, pathname } = url_1.default.parse(ws.url);
const url = `${protocol}//${host}${pathname}`;
super(reason
? `WebSocket connection to [${url}] got error [${reason?.message ?? reason}]`
: `Cannot connect webSocket to [${url}]`);
this.ws = ws;
this.reason = reason;
this.url = 'none';
Object.assign(this, { url });
}
static build(ws, predicate) {
const reason = predicate instanceof Error
? predicate
: predicate
? new Error(String(predicate))
: null;
return reason instanceof WebSocketConnectionError
? reason
: new WebSocketConnectionError(ws, reason ?? ws.error ?? new Error('Unknown'));
}
}
exports.WebSocketConnectionError = WebSocketConnectionError;
//# sourceMappingURL=websocket-connection.error.js.map