diff --git a/src/http/fetcher.test.ts b/src/http/fetcher.test.ts index 81c0bb35..f6b921e3 100644 --- a/src/http/fetcher.test.ts +++ b/src/http/fetcher.test.ts @@ -154,16 +154,16 @@ test('mocking fetch', async () => { // This is how "default tooling" prints errors // eslint-disable-next-line @typescript-eslint/no-base-to-string - expect(String(err)).toMatchInlineSnapshot(`"HttpRequestError: 500 GET some"`) + expect(String(err)).toMatchInlineSnapshot(`"HttpRequestError: 500 GET some 93 ms"`) // This is how Jest prints errors - expect(err).toMatchInlineSnapshot('[HttpRequestError: 500 GET some]') + expect(err).toMatchInlineSnapshot(`[HttpRequestError: 500 GET some 93 ms]`) // This is how NC-ecosystem-aware consumer prints errors (e.g with Cause) expect(_stringify(err)).toMatchInlineSnapshot(` - "HttpRequestError: 500 GET some - Caused by: AppError: aya-baya" - `) +"HttpRequestError: 500 GET some 93 ms +Caused by: AppError: aya-baya" +`) err.data.requestDuration = 10 // mock stability expect(err.data).toMatchInlineSnapshot(` { @@ -248,7 +248,7 @@ test('json parse error', async () => { url: 'some', }) _assertIsError(err) - expect(String(err)).toMatchInlineSnapshot(`"HttpRequestError: GET some"`) + expect(String(err)).toMatchInlineSnapshot(`"HttpRequestError: GET some 5 ms"`) _assertIsErrorObject(err.cause) delete err.cause.stack expect(err.cause).toMatchInlineSnapshot(` @@ -262,9 +262,9 @@ test('json parse error', async () => { `) expect(_stringify(err)).toMatchInlineSnapshot(` - "HttpRequestError: GET some - Caused by: JsonParseError: Failed to parse: some text" - `) +"HttpRequestError: GET some 5 ms +Caused by: JsonParseError: Failed to parse: some text" +`) }) test('paginate', async () => { @@ -383,9 +383,9 @@ test('tryFetch', async () => { expectTypeOf(err).toEqualTypeOf() expect(err.data.requestMethod).toBe('POST') expect(_stringify(err)).toMatchInlineSnapshot(` - "HttpRequestError: 500 POST https://example.com/ - Caused by: Error: bad" - `) +"HttpRequestError: 500 POST https://example.com/ 0 ms +Caused by: Error: bad" +`) } else { expectTypeOf(data).toEqualTypeOf<{ ok: boolean }>() } @@ -460,9 +460,9 @@ test('expectError', async () => { const err = await fetcher.expectError({ url: 'someUrl' }) expect(_stringify(err)).toMatchInlineSnapshot(` - "HttpRequestError: 500 GET someUrl - Caused by: AppError: some" - `) +"HttpRequestError: 500 GET someUrl 0 ms +Caused by: AppError: some" +`) // 2. Pass should throw jest diff --git a/src/http/fetcher.ts b/src/http/fetcher.ts index 47fa3f21..9453c2c6 100644 --- a/src/http/fetcher.ts +++ b/src/http/fetcher.ts @@ -409,8 +409,8 @@ export class Fetcher { ' <<', res.fetchResponse.status, res.signature, - retryAttempt && `try#${retryAttempt + 1}/${req.retry.count + 1}`, _since(res.req.started), + retryAttempt && `try#${retryAttempt + 1}/${req.retry.count + 1}`, ] .filter(Boolean) .join(' '), @@ -466,7 +466,9 @@ export class Fetcher { responseStatusCode = 0 } - const message = [res.statusCode, res.signature].filter(Boolean).join(' ') + const message = [res.statusCode, res.signature, _since(res.req.started)] + .filter(Boolean) + .join(' ') res.err = new HttpRequestError( message,