Added extra details in the error info field for RPC errors.

This commit is contained in:
Richard Moore 2023-03-20 14:42:19 -04:00
parent 6e01e5448f
commit 30ffa78d14

View File

@ -415,7 +415,7 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
// No result; the node failed us in unexpected ways // No result; the node failed us in unexpected ways
if (resp == null) { if (resp == null) {
return reject(new Error("@TODO: no result")); return reject(makeError("no response from server", "BAD_DATA", { value: result, info: { payload } }));
} }
// The response is an error // The response is an error
@ -797,6 +797,7 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
if (!msg.match(/revert/i) && msg.match(/insufficient funds/i)) { if (!msg.match(/revert/i) && msg.match(/insufficient funds/i)) {
return makeError("insufficient funds", "INSUFFICIENT_FUNDS", { return makeError("insufficient funds", "INSUFFICIENT_FUNDS", {
transaction: ((<any>payload).params[0]), transaction: ((<any>payload).params[0]),
info: { payload, error }
}); });
} }
} }
@ -846,17 +847,17 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
} }
if (message.match(/nonce/i) && message.match(/too low/i)) { if (message.match(/nonce/i) && message.match(/too low/i)) {
return makeError("nonce has already been used", "NONCE_EXPIRED", { transaction }); return makeError("nonce has already been used", "NONCE_EXPIRED", { transaction, info: { error } });
} }
// "replacement transaction underpriced" // "replacement transaction underpriced"
if (message.match(/replacement transaction/i) && message.match(/underpriced/i)) { if (message.match(/replacement transaction/i) && message.match(/underpriced/i)) {
return makeError("replacement fee too low", "REPLACEMENT_UNDERPRICED", { transaction }); return makeError("replacement fee too low", "REPLACEMENT_UNDERPRICED", { transaction, info: { error } });
} }
if (message.match(/only replay-protected/i)) { if (message.match(/only replay-protected/i)) {
return makeError("legacy pre-eip-155 transactions not supported", "UNSUPPORTED_OPERATION", { return makeError("legacy pre-eip-155 transactions not supported", "UNSUPPORTED_OPERATION", {
operation: method, info: { transaction } operation: method, info: { transaction, info: { error } }
}); });
} }
} }