Skip to content

Commit

Permalink
fix: response the error code instead only the message
Browse files Browse the repository at this point in the history
  • Loading branch information
andybin-cdc committed May 17, 2022
1 parent 6e4f3ef commit 6bcb848
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/clients/core/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class EventManager {

eventEmitters.forEach((eventEmitter: IEventEmitter) => {
if (isJsonRpcResponseError(payload)) {
const error = new Error(payload.error.message);
eventEmitter.callback(error, null);
eventEmitter.callback(payload.error, null);
} else {
eventEmitter.callback(null, payload);
}
Expand Down
11 changes: 6 additions & 5 deletions packages/clients/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
IQRCodeModalOptions,
IWalletConnectSessionWallet,
IJsonRpcRequestSessionInfo,
IJsonRpcErrorMessage,
} from "@deficonnect/types";
import {
parsePersonalSign,
Expand Down Expand Up @@ -397,7 +398,7 @@ class Connector implements IConnector {

// -- public ---------------------------------------------------------- //

public on(event: string, callback: (error: Error | null, payload: any | null) => void): void {
public on(event: string, callback: (error: IJsonRpcErrorMessage | null, payload: any | null) => void): void {
const eventEmitter = {
event,
callback,
Expand Down Expand Up @@ -789,7 +790,7 @@ class Connector implements IConnector {
});

return new Promise((resolve, reject) => {
this._subscribeToResponse(request.id, (error: Error | null, payload: any | null) => {
this._subscribeToResponse(request.id, (error: IJsonRpcErrorMessage | null, payload: any | null) => {
if (error) {
reject(error);
return;
Expand Down Expand Up @@ -1104,7 +1105,7 @@ class Connector implements IConnector {

private _subscribeToResponse(
id: number,
callback: (error: Error | null, payload: any | null) => void,
callback: (error: IJsonRpcErrorMessage | null, payload: any | null) => void,
) {
this.on(`response:${id}`, callback);
}
Expand Down Expand Up @@ -1135,7 +1136,7 @@ class Connector implements IConnector {
if (payload.result) {
resolve(payload.result);
} else if (payload.error && payload.error.message) {
reject(new Error(payload.error.message));
reject(payload.error);
} else {
reject(new Error(ERROR_INVALID_RESPONSE));
}
Expand Down Expand Up @@ -1356,7 +1357,7 @@ class Connector implements IConnector {
language: pushServerOpts.language || "",
};

this.on("connect", async (error: Error | null, payload: any) => {
this.on("connect", async (error: IJsonRpcErrorMessage | null, payload: any) => {
if (error) {
throw error;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/helpers/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare module "@deficonnect/types" {
readonly pending: boolean;
session: IWalletConnectSession;

on(event: string, callback: (error: Error | null, payload: any | null) => void): void;
on(event: string, callback: (error: IJsonRpcErrorMessage | null, payload: any | null) => void): void;
connect(opts?: ICreateSessionOptions): Promise<ISessionStatus>;
createSession(opts?: ICreateSessionOptions): Promise<void>;
approveSession(sessionStatus: ISessionStatus): void;
Expand Down Expand Up @@ -206,7 +206,7 @@ declare module "@deficonnect/types" {

export interface IEventEmitter {
event: string;
callback: (error: Error | null, request: any | null) => void;
callback: (error: IJsonRpcErrorMessage | null, request: any | null) => void;
}

export interface IRequiredParamsResult {
Expand Down

0 comments on commit 6bcb848

Please sign in to comment.