Better way to throw websocket exceptions
This commit is contained in:
parent
d1db1195ed
commit
c038c07b06
2 changed files with 10 additions and 10 deletions
|
@ -33,9 +33,10 @@ export class HTTPError extends Error {
|
|||
headers: HTTPErrorHeadersType;
|
||||
response?: unknown;
|
||||
stack?: string;
|
||||
cause?: unknown;
|
||||
}
|
||||
) {
|
||||
super(`${message}; code: ${options.code}`);
|
||||
super(`${message}; code: ${options.code}`, { cause: options.cause });
|
||||
|
||||
const { code: providedCode, headers, response, stack } = options;
|
||||
|
||||
|
|
|
@ -100,17 +100,16 @@ export function connect<Resource extends IResource>({
|
|||
reject(translatedError);
|
||||
});
|
||||
|
||||
client.on('connectFailed', e => {
|
||||
client.on('connectFailed', originalErr => {
|
||||
Timers.clearTimeout(timer);
|
||||
|
||||
reject(
|
||||
new HTTPError('connectResource: connectFailed', {
|
||||
const err = new HTTPError('connectResource: connectFailed', {
|
||||
code: -1,
|
||||
headers: {},
|
||||
response: e.toString(),
|
||||
stack,
|
||||
})
|
||||
);
|
||||
cause: originalErr,
|
||||
});
|
||||
reject(err);
|
||||
});
|
||||
|
||||
return new AbortableProcess<Resource>(
|
||||
|
|
Loading…
Reference in a new issue