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, });