Skip to content

Commit

Permalink
include response headers in error info
Browse files Browse the repository at this point in the history
  • Loading branch information
rnons authored and zfy0701 committed Jul 3, 2024
1 parent 502a314 commit d05e368
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src.ts/providers/provider-jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,8 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
*/
getRpcError(payload: JsonRpcPayload, _error: JsonRpcError): Error {
const { method } = payload;
const { error } = _error;
// @ts-expect-error xx
const { error, headers } = _error;

if (method === "eth_estimateGas" && error.message) {
const msg = error.message;
Expand All @@ -981,7 +982,7 @@ export abstract class JsonRpcApiProvider extends AbstractProvider {
((<any>payload).params[0]),
(result ? result.data: null)
);
e.info = { error, payload };
e.info = { error, payload, headers };
return e;
}

Expand Down Expand Up @@ -1236,6 +1237,16 @@ export class JsonRpcProvider extends JsonRpcApiPollingProvider {

let resp = response.bodyJson;
if (!Array.isArray(resp)) { resp = [ resp ]; }
resp.forEach((res: any) => {
if ("error" in res) {
res.headers = {}
for (const [key, value] of Object.entries(response.headers)) {
if (key.toLowerCase().includes('sentio')) {
res.headers[key] = value
}
}
}
})

return resp;
}
Expand Down

0 comments on commit d05e368

Please sign in to comment.