From 35ad12735355b9b51f969f069c514e96a6863423 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Fri, 11 Oct 2024 14:57:39 -0400 Subject: [PATCH] feat(replay): Do not log "timeout while trying to read resp body" as exception Change this to be a warn level log instead of an exception (which gets captured to Sentry). Since this is an error we are throwing ourselves and it is to be expected, no need to treat as an exception. This also adds a new meta string to differentiate from an error while parsing. This means we can show a more specific error message on the frontend. --- .../replay-internal/src/coreHandlers/util/fetchUtils.ts | 7 +++++-- packages/replay-internal/src/types/request.ts | 1 + .../test/unit/coreHandlers/util/fetchUtils.test.ts | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/replay-internal/src/coreHandlers/util/fetchUtils.ts b/packages/replay-internal/src/coreHandlers/util/fetchUtils.ts index 6502206b58b6..f218f4ab9b35 100644 --- a/packages/replay-internal/src/coreHandlers/util/fetchUtils.ts +++ b/packages/replay-internal/src/coreHandlers/util/fetchUtils.ts @@ -209,6 +209,11 @@ async function _parseFetchResponseBody(response: Response): Promise<[string | un const text = await _tryGetResponseText(res); return [text]; } catch (error) { + if (error instanceof Error && error.message.indexOf('Timeout') > -1) { + DEBUG_BUILD && logger.warn('Parsing text body from response timed out'); + return [undefined, 'BODY_PARSE_TIMEOUT']; + } + DEBUG_BUILD && logger.exception(error, 'Failed to get text body from response'); return [undefined, 'BODY_PARSE_ERROR']; } @@ -299,8 +304,6 @@ function _tryGetResponseText(response: Response): Promise { ) .finally(() => clearTimeout(timeout)); }); - - return _getResponseText(response); } async function _getResponseText(response: Response): Promise { diff --git a/packages/replay-internal/src/types/request.ts b/packages/replay-internal/src/types/request.ts index 60c25a55ce44..c04b57409d0c 100644 --- a/packages/replay-internal/src/types/request.ts +++ b/packages/replay-internal/src/types/request.ts @@ -8,6 +8,7 @@ export type NetworkMetaWarning = | 'TEXT_TRUNCATED' | 'URL_SKIPPED' | 'BODY_PARSE_ERROR' + | 'BODY_PARSE_TIMEOUT' | 'UNPARSEABLE_BODY_TYPE'; interface NetworkMeta { diff --git a/packages/replay-internal/test/unit/coreHandlers/util/fetchUtils.test.ts b/packages/replay-internal/test/unit/coreHandlers/util/fetchUtils.test.ts index ffd665471975..4da9ecab639e 100644 --- a/packages/replay-internal/test/unit/coreHandlers/util/fetchUtils.test.ts +++ b/packages/replay-internal/test/unit/coreHandlers/util/fetchUtils.test.ts @@ -132,7 +132,7 @@ describe('Unit | coreHandlers | util | fetchUtils', () => { ]); expect(res).toEqual({ - _meta: { warnings: ['BODY_PARSE_ERROR'] }, + _meta: { warnings: ['BODY_PARSE_TIMEOUT'] }, headers: {}, size: undefined, });