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 21, 2023
1 parent f443070 commit 8e14099
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 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 @@ -60,7 +60,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
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
5 changes: 3 additions & 2 deletions src/transports/WebSocketTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class WebSocketTransport extends Transport {
this.connection.send(JSON.stringify(this.parseData(data)));
this.transportRequestManager.settlePendingRequest(notifications);
} catch (err) {
const jsonError = new JSONRPCError((err as any).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);

Expand Down

0 comments on commit 8e14099

Please sign in to comment.