diff --git a/__tests__/config/jest.setup.ts b/__tests__/config/jest.setup.ts index a0603619b..aa784e2bd 100644 --- a/__tests__/config/jest.setup.ts +++ b/__tests__/config/jest.setup.ts @@ -9,27 +9,51 @@ import 'isomorphic-fetch'; /* eslint-disable no-console */ import { register } from 'fetch-intercept'; +const util = require('util'); + jest.setTimeout(50 * 60 * 1000); +const combiner: object[] = []; + if (process.env.DEBUG === 'true') { register({ request(url, config) { - console.log('[fetch.request]', [url, config]); + const body = JSON.parse(config.body); + combiner.push({ + request: { + url, + method: config.method, + body, + }, + }); return [url, config]; }, requestError(error) { - console.log('[fetch.requestError]', error); + const match: any = combiner.find((it: any) => typeof it.result === 'undefined'); + match.result = error; + console.log('[fetch.requestError]', match); return Promise.reject(error); }, response(response) { - console.log('[fetch.response]', response); + const cloned = response.clone(); + cloned.json().then(({ result }) => { + const match: any = combiner.find((it: any) => typeof it.result === 'undefined'); + if (match && 'request' in match) { + match.result = result; + console.log(util.inspect(match, false, null, true /* enable colors */)); + } else { + console.log(result); + } + }); return response; }, responseError(error) { - console.log('[fetch.responseError]', error); + const match: any = combiner.find((it: any) => typeof it.result === 'undefined'); + match.result = error; + console.log('[fetch.responseError]', match); return Promise.reject(error); }, }); diff --git a/src/channel/rpc_0_6.ts b/src/channel/rpc_0_6.ts index 012166b0b..d2b87e82b 100644 --- a/src/channel/rpc_0_6.ts +++ b/src/channel/rpc_0_6.ts @@ -101,7 +101,8 @@ export class RpcChannel { if (rpcError) { const { code, message, data } = rpcError; throw new LibraryError( - `RPC: ${method} with params ${stringify(params)}\n ${code}: ${message}: ${stringify(data)}` + `RPC: ${method} with params ${stringify(params, null, 2)}\n + ${code}: ${message}: ${stringify(data)}` ); } if (otherError instanceof LibraryError) {