Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.

Commit 2cdcf45

Browse files
committed
Prevent promise resolution function from being called twice
1 parent a18233b commit 2cdcf45

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

src/JsonRpcEngine.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -408,27 +408,27 @@ export class JsonRpcEngine extends SafeEventEmitter {
408408
returnHandler?: JsonRpcEngineReturnHandler,
409409
) => {
410410
if (res.error) {
411-
end(res.error);
412-
} else {
413-
if (returnHandler) {
414-
if (typeof returnHandler !== 'function') {
415-
end(
416-
new EthereumRpcError(
417-
errorCodes.rpc.internal,
418-
`JsonRpcEngine: "next" return handlers must be functions. ` +
419-
`Received "${typeof returnHandler}" for request:\n${jsonify(
420-
req,
421-
)}`,
422-
{ request: req },
423-
),
424-
);
425-
}
426-
returnHandlers.push(returnHandler);
427-
}
411+
return end(res.error);
412+
}
428413

429-
// False indicates that the request should not end
430-
resolve([null, false]);
414+
if (returnHandler) {
415+
if (typeof returnHandler !== 'function') {
416+
return end(
417+
new EthereumRpcError(
418+
errorCodes.rpc.internal,
419+
`JsonRpcEngine: "next" return handlers must be functions. ` +
420+
`Received "${typeof returnHandler}" for request:\n${jsonify(
421+
req,
422+
)}`,
423+
{ request: req },
424+
),
425+
);
426+
}
427+
returnHandlers.push(returnHandler);
431428
}
429+
430+
// False indicates that the request should not end
431+
return resolve([null, false]);
432432
};
433433

434434
try {

0 commit comments

Comments
 (0)