Skip to content

Commit

Permalink
Bubble up errors by passing them through.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjones1 committed Mar 17, 2022
1 parent f1c9b04 commit 2bb759f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/transports/EventEmitterTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class EventEmitterTransport extends Transport {
this.transportRequestManager.settlePendingRequest(notifications);
return prom;
} catch (e) {
const responseErr = new JSONRPCError(e.message, ERR_UNKNOWN, e);
const responseErr = e instanceof JSONRPCError
? e
: new JSONRPCError(e.message, ERR_UNKNOWN, e);
this.transportRequestManager.settlePendingRequest(notifications, responseErr);
return Promise.reject(responseErr);
}
Expand Down
4 changes: 3 additions & 1 deletion src/transports/HTTPTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class HTTPTransport extends Transport {
return Promise.reject(responseErr);
}
} catch (e) {
const responseErr = new JSONRPCError(e.message, ERR_UNKNOWN, e);
const responseErr = e instanceof JSONRPCError
? e
: new JSONRPCError(e.message, ERR_UNKNOWN, e);
this.transportRequestManager.settlePendingRequest(notifications, responseErr);
this.transportRequestManager.settlePendingRequest(getBatchRequests(data), responseErr);
return Promise.reject(responseErr);
Expand Down
4 changes: 3 additions & 1 deletion src/transports/TransportRequestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export class TransportRequestManager {
}
return this.resolveRes(data, emitError);
} catch (e) {
const err = new JSONRPCError("Bad response format", ERR_UNKNOWN, payload);
const err = e instanceof JSONRPCError
? e
: new JSONRPCError("Bad response format", ERR_UNKNOWN, payload);
if (emitError) {
this.transportEventChannel.emit("error", err);
}
Expand Down
4 changes: 3 additions & 1 deletion src/transports/WebSocketTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class WebSocketTransport extends Transport {
const notifications = getNotifications(data);
this.connection.send(JSON.stringify(this.parseData(data)), (err?: Error) => {
if (err) {
const jsonError = new JSONRPCError(err.message, ERR_UNKNOWN, err);
const jsonError = err instanceof JSONRPCError
? err
: new JSONRPCError(e.message, ERR_UNKNOWN, err);
this.transportRequestManager.settlePendingRequest(notifications, jsonError);
this.transportRequestManager.settlePendingRequest(getBatchRequests(data), jsonError);
prom = Promise.reject(jsonError);
Expand Down

0 comments on commit 2bb759f

Please sign in to comment.