@@ -26,7 +26,7 @@ import {
26
26
*/
27
27
export async function captureFetchBreadcrumbToReplay (
28
28
breadcrumb : Breadcrumb & { data : FetchBreadcrumbData } ,
29
- hint : FetchHint ,
29
+ hint : Partial < FetchHint > ,
30
30
options : ReplayNetworkOptions & {
31
31
textEncoder : TextEncoderInternal ;
32
32
replay : ReplayContainer ;
@@ -50,12 +50,12 @@ export async function captureFetchBreadcrumbToReplay(
50
50
*/
51
51
export function enrichFetchBreadcrumb (
52
52
breadcrumb : Breadcrumb & { data : FetchBreadcrumbData } ,
53
- hint : FetchHint ,
53
+ hint : Partial < FetchHint > ,
54
54
options : { textEncoder : TextEncoderInternal } ,
55
55
) : void {
56
56
const { input, response } = hint ;
57
57
58
- const body = _getFetchRequestArgBody ( input ) ;
58
+ const body = input ? _getFetchRequestArgBody ( input ) : undefined ;
59
59
const reqSize = getBodySize ( body , options . textEncoder ) ;
60
60
61
61
const resSize = response ? parseContentLengthHeader ( response . headers . get ( 'content-length' ) ) : undefined ;
@@ -70,12 +70,13 @@ export function enrichFetchBreadcrumb(
70
70
71
71
async function _prepareFetchData (
72
72
breadcrumb : Breadcrumb & { data : FetchBreadcrumbData } ,
73
- hint : FetchHint ,
73
+ hint : Partial < FetchHint > ,
74
74
options : ReplayNetworkOptions & {
75
75
textEncoder : TextEncoderInternal ;
76
76
} ,
77
77
) : Promise < ReplayNetworkRequestData > {
78
- const { startTimestamp, endTimestamp } = hint ;
78
+ const now = Date . now ( ) ;
79
+ const { startTimestamp = now , endTimestamp = now } = hint ;
79
80
80
81
const {
81
82
url,
@@ -106,10 +107,10 @@ async function _prepareFetchData(
106
107
107
108
function _getRequestInfo (
108
109
{ networkCaptureBodies, networkRequestHeaders } : ReplayNetworkOptions ,
109
- input : FetchHint [ 'input' ] ,
110
+ input : FetchHint [ 'input' ] | undefined ,
110
111
requestBodySize ?: number ,
111
112
) : ReplayNetworkRequestOrResponse | undefined {
112
- const headers = getRequestHeaders ( input , networkRequestHeaders ) ;
113
+ const headers = input ? getRequestHeaders ( input , networkRequestHeaders ) : { } ;
113
114
114
115
if ( ! networkCaptureBodies ) {
115
116
return buildNetworkRequestOrResponse ( headers , requestBodySize , undefined ) ;
@@ -130,16 +131,16 @@ async function _getResponseInfo(
130
131
} : ReplayNetworkOptions & {
131
132
textEncoder : TextEncoderInternal ;
132
133
} ,
133
- response : Response ,
134
+ response : Response | undefined ,
134
135
responseBodySize ?: number ,
135
136
) : Promise < ReplayNetworkRequestOrResponse | undefined > {
136
137
if ( ! captureDetails && responseBodySize !== undefined ) {
137
138
return buildSkippedNetworkRequestOrResponse ( responseBodySize ) ;
138
139
}
139
140
140
- const headers = getAllHeaders ( response . headers , networkResponseHeaders ) ;
141
+ const headers = response ? getAllHeaders ( response . headers , networkResponseHeaders ) : { } ;
141
142
142
- if ( ! networkCaptureBodies && responseBodySize !== undefined ) {
143
+ if ( ! response || ( ! networkCaptureBodies && responseBodySize !== undefined ) ) {
143
144
return buildNetworkRequestOrResponse ( headers , responseBodySize , undefined ) ;
144
145
}
145
146
@@ -163,7 +164,8 @@ async function _getResponseInfo(
163
164
}
164
165
165
166
return buildNetworkRequestOrResponse ( headers , size , undefined ) ;
166
- } catch {
167
+ } catch ( error ) {
168
+ __DEBUG_BUILD__ && logger . warn ( '[Replay] Failed to serialize response body' , error ) ;
167
169
// fallback
168
170
return buildNetworkRequestOrResponse ( headers , responseBodySize , undefined ) ;
169
171
}
0 commit comments