@@ -3,6 +3,12 @@ import includes from '@bugsnag/core/lib/es-utils/includes'
33
44const BREADCRUMB_TYPE = 'request'
55
6+ interface GlobalWithFetchAndXHR {
7+ fetch : typeof fetch
8+ XMLHttpRequest : typeof XMLHttpRequest
9+ WeakMap : typeof WeakMap
10+ }
11+
612interface InternalClient extends Client {
713 _logger : Logger
814 _config : Required < Config >
@@ -14,7 +20,7 @@ type FetchArguments = Parameters<Window['fetch']>
1420/*
1521 * Leaves breadcrumbs when network requests occur
1622 */
17- export default ( _ignoredUrls = [ ] , win = window ) : Plugin => {
23+ export default ( _ignoredUrls = [ ] , win : GlobalWithFetchAndXHR = window ) : Plugin => {
1824 let restoreFunctions : Array < ( ) => void > = [ ]
1925 const plugin : Plugin = {
2026 load : client => {
@@ -166,7 +172,7 @@ export default (_ignoredUrls = [], win = window): Plugin => {
166172 // pass through to native fetch
167173 oldFetch ( ...args )
168174 . then ( response => {
169- handleFetchSuccess ( response , method , url , getDuration ( requestStart ) )
175+ handleFetchSuccess ( response , String ( method ) , String ( url ) , getDuration ( requestStart ) )
170176 resolve ( response )
171177 } )
172178 . catch ( error => {
@@ -183,11 +189,11 @@ export default (_ignoredUrls = [], win = window): Plugin => {
183189 }
184190 }
185191
186- const handleFetchSuccess = ( response : Response , method : string | undefined , url : string | URL | null , duration : number ) => {
192+ const handleFetchSuccess = ( response : Response , method : string , url : string , duration : number ) => {
187193 const metadata = {
188- method : String ( method ) ,
194+ method,
189195 status : response . status ,
190- url : String ( url ) ,
196+ url,
191197 duration : duration
192198 }
193199 if ( response . status >= 400 ) {
@@ -199,7 +205,7 @@ export default (_ignoredUrls = [], win = window): Plugin => {
199205 }
200206
201207 const handleFetchError = ( method : string , url : string , duration : number ) => {
202- internalClient . leaveBreadcrumb ( 'fetch() error' , { method : String ( method ) , url : String ( url ) , duration : duration } , BREADCRUMB_TYPE )
208+ internalClient . leaveBreadcrumb ( 'fetch() error' , { method, url, duration : duration } , BREADCRUMB_TYPE )
203209 }
204210 }
205211 }
0 commit comments