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:
@@ -1,6 +1,7 @@
|
|||||||
// Copyright 2017-2025 @polkadot/rpc-provider authors & contributors
|
// Copyright 2017-2025 @polkadot/rpc-provider authors & contributors
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// 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 type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, ProviderStats } from '../types.js';
|
||||||
|
|
||||||
import { logger, noop, stringify } from '@polkadot/util';
|
import { logger, noop, stringify } from '@polkadot/util';
|
||||||
@@ -185,7 +186,18 @@ export class HttpProvider implements ProviderInterface {
|
|||||||
this.#stats.active.requests--;
|
this.#stats.active.requests--;
|
||||||
this.#stats.total.errors++;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
import type { Class } from '@polkadot/util/types';
|
import type { Class } from '@polkadot/util/types';
|
||||||
|
import type RpcError from '../coder/error.js';
|
||||||
import type { EndpointStats, JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, ProviderStats } from '../types.js';
|
import type { EndpointStats, JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, ProviderStats } from '../types.js';
|
||||||
|
|
||||||
import { EventEmitter } from 'eventemitter3';
|
import { EventEmitter } from 'eventemitter3';
|
||||||
@@ -372,7 +373,12 @@ export class WsProvider implements ProviderInterface {
|
|||||||
this.#endpointStats.errors++;
|
this.#endpointStats.errors++;
|
||||||
this.#stats.total.errors++;
|
this.#stats.total.errors++;
|
||||||
|
|
||||||
reject(error);
|
const rpcError: RpcError = error as RpcError;
|
||||||
|
const failedRequest = `\nFailed WS Request: ${JSON.stringify({ method, params })}`;
|
||||||
|
|
||||||
|
// Provide WS Request alongside the error
|
||||||
|
rpcError.message = `${rpcError.message}${failedRequest}`;
|
||||||
|
reject(rpcError);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user