Skip to content

Commit

Permalink
fix: add support for out of band errors with no id
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejonas committed Sep 10, 2021
1 parent 9bc2827 commit 0c4a63d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/containers/Inspector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const defaultTransports: ITransport[] = [
},
];

const errorToJSON = (error: JSONRPCError | any, id: string | number): any => {
const errorToJSON = (error: JSONRPCError | any, id?: string | number | null): any => {
const isError = error instanceof Error;
if (!isError) {
return;
Expand Down Expand Up @@ -256,6 +256,17 @@ const Inspector: React.FC<IProps> = (props) => {
setLogs((prevLogs) => [...prevLogs, notificationObj]);
setTabLogs(tabIndex, [...(tabs[tabIndex].logs || []), notificationObj]);
});
transport.subscribe("error", (error: any) => {
const responseTimestamp = new Date();
const notificationObj: JSONRPCLog = {
type: "response",
method: "",
timestamp: responseTimestamp,
payload: errorToJSON(error, error.id),
};
setLogs((prevLogs) => [...prevLogs, notificationObj]);
setTabLogs(tabIndex, [...(tabs[tabIndex].logs || []), notificationObj]);
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [transport]);
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const getTransportFromType = async (
intermediateTransport.subscribe("notification", (data: IJSONRPCNotificationResponse) => {
this.transportRequestManager.transportEventChannel.emit("notification", data);
});
intermediateTransport.subscribe("error", (data: JSONRPCError) => {
this.transportRequestManager.transportEventChannel.emit("error", data);
});
return results;
}
public sendData(data: IJSONRPCData): Promise<any> {
Expand Down

0 comments on commit 0c4a63d

Please sign in to comment.