Log Http/Ws request on error (#6091)

* Log Http request alongside HTTP error

* Log WS request alongside WS error and improve http

* lint
This commit is contained in:
Valentin Fernandez
2025-02-11 08:08:31 -05:00
committed by GitHub
parent 25037ae918
commit 5edb5d9b57
2 changed files with 20 additions and 2 deletions
+13 -1
View File
@@ -1,6 +1,7 @@
// Copyright 2017-2025 @polkadot/rpc-provider authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type RpcError from '../coder/error.js';
import type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, ProviderStats } from '../types.js';
import { logger, noop, stringify } from '@polkadot/util';
@@ -185,7 +186,18 @@ export class HttpProvider implements ProviderInterface {
this.#stats.active.requests--;
this.#stats.total.errors++;
throw e;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { method, params } = JSON.parse(body);
const rpcError: RpcError = e as RpcError;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const failedRequest = `\nFailed HTTP Request: ${JSON.stringify({ method, params })}`;
// Provide HTTP Request alongside the error
rpcError.message = `${rpcError.message}${failedRequest}`;
throw rpcError;
}
}