Only format error log, upstream error from core (#2089)
* Only format error log, upstream error from core * Remove (now unused) wrapping info
This commit is contained in:
@@ -29,12 +29,12 @@ const EMPTY_META = {
|
||||
|
||||
// utility method to create a nicely-formatted error
|
||||
/** @internal */
|
||||
function createErrorMessage (method: string, { params, type }: DefinitionRpc, error: Error): string {
|
||||
function logErrorMessage (method: string, { params, type }: DefinitionRpc, error: Error): void {
|
||||
const inputs = params.map(({ isOptional, name, type }): string =>
|
||||
`${name}${isOptional ? '?' : ''}: ${type}`
|
||||
).join(', ');
|
||||
|
||||
return `${method}(${inputs}): ${type}:: ${error.message}`;
|
||||
l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,12 +191,9 @@ export default class Rpc implements RpcInterface {
|
||||
: this.formatOutput(def, params, result)
|
||||
),
|
||||
catchError((error): any => {
|
||||
const message = createErrorMessage(method, def, error);
|
||||
logErrorMessage(method, def, error);
|
||||
|
||||
// don't scare with old nodes, this is handled transparently
|
||||
rpcName !== 'rpc_methods' && l.error(message);
|
||||
|
||||
return throwError(new Error(message));
|
||||
return throwError(error);
|
||||
}),
|
||||
publishReplay(1), // create a Replay(1)
|
||||
refCount() // Unsubscribe WS when there are no more subscribers
|
||||
@@ -232,11 +229,9 @@ export default class Rpc implements RpcInterface {
|
||||
// Have at least an empty promise, as used in the unsubscribe
|
||||
let subscriptionPromise: Promise<number | void> = Promise.resolve();
|
||||
const errorHandler = (error: Error): void => {
|
||||
const message = createErrorMessage(method, def, error);
|
||||
logErrorMessage(method, def, error);
|
||||
|
||||
l.error(message);
|
||||
|
||||
observer.error(new Error(message));
|
||||
observer.error(error);
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -244,7 +239,7 @@ export default class Rpc implements RpcInterface {
|
||||
const paramsJson = params.map((param): AnyJson => param.toJSON());
|
||||
const update = (error?: Error | null, result?: any): void => {
|
||||
if (error) {
|
||||
l.error(createErrorMessage(method, def, error));
|
||||
logErrorMessage(method, def, error);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -285,7 +280,7 @@ export default class Rpc implements RpcInterface {
|
||||
? this.provider.unsubscribe(subType, unsubName, subscriptionId)
|
||||
: Promise.resolve(false)
|
||||
)
|
||||
.catch((error: Error): void => l.error(createErrorMessage(method, def, error)));
|
||||
.catch((error: Error): void => logErrorMessage(method, def, error));
|
||||
};
|
||||
}).pipe(drr());
|
||||
};
|
||||
|
||||
@@ -39,19 +39,6 @@ describe('methodSend', (): void => {
|
||||
rpc = new Rpc(registry, provider);
|
||||
});
|
||||
|
||||
it('wraps errors with the call signature', (done): void => {
|
||||
// private access
|
||||
const method = (rpc as any).createMethodSend('test', 'blah', methods.blah);
|
||||
|
||||
method().subscribe(
|
||||
(): void => undefined,
|
||||
(error: Error): void => {
|
||||
expect(error.message).toMatch(/blah\(foo: Bytes\): Bytes/);
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('checks for mismatched parameters', (done): void => {
|
||||
// private method
|
||||
const method = (rpc as any).createMethodSend('test', 'bleh', methods.bleh);
|
||||
|
||||
@@ -17,7 +17,7 @@ function formatErrorData (data?: string | number): string {
|
||||
|
||||
// We need some sort of cut-off here since these can be very large and
|
||||
// very nested, pick a number and trim the result display to it
|
||||
return `: ${formatted.substr(0, 35)}`;
|
||||
return `: ${formatted.substr(0, 100)}`;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
Reference in New Issue
Block a user