1- import type { ConsoleLevel , Logger } from '@sentry/core' ;
1+ import { logger } from '@sentry/core' ;
2+ import type { Logger } from '@sentry/core' ;
23import { DEBUG_BUILD } from './debug-build' ;
34import type { NetworkMetaWarning } from './types' ;
45
5- type ReplayConsoleLevels = Extract < ConsoleLevel , 'info' | 'warn' | 'error' | 'log' > ;
6- type LoggerMethod = ( ...args : unknown [ ] ) => void ;
7- type LoggerConsoleMethods = Record < ReplayConsoleLevels , LoggerMethod > ;
8-
9- interface LoggerConfig {
10- captureExceptions : boolean ;
11- traceInternals : boolean ;
12- }
13-
14- // Duplicate from replay-internal
15- interface ReplayLogger extends LoggerConsoleMethods {
16- /**
17- * Calls `logger.info` but saves breadcrumb in the next tick due to race
18- * conditions before replay is initialized.
19- */
20- infoTick : LoggerMethod ;
21- /**
22- * Captures exceptions (`Error`) if "capture internal exceptions" is enabled
23- */
24- exception : LoggerMethod ;
25- /**
26- * Configures the logger with additional debugging behavior
27- */
28- setConfig ( config : Partial < LoggerConfig > ) : void ;
29- }
30-
31- function _serializeFormData ( formData : FormData ) : string {
32- // This is a bit simplified, but gives us a decent estimate
33- // This converts e.g. { name: 'Anne Smith', age: 13 } to 'name=Anne+Smith&age=13'
6+ /**
7+ * Serializes FormData.
8+ *
9+ * This is a bit simplified, but gives us a decent estimate.
10+ * This converts e.g. { name: 'Anne Smith', age: 13 } to 'name=Anne+Smith&age=13'.
11+ *
12+ */
13+ export function serializeFormData ( formData : FormData ) : string {
3414 // @ts -expect-error passing FormData to URLSearchParams actually works
3515 return new URLSearchParams ( formData ) . toString ( ) ;
3616}
3717
3818/** Get the string representation of a body. */
39- export function getBodyString (
40- body : unknown ,
41- logger ?: Logger | ReplayLogger ,
42- ) : [ string | undefined , NetworkMetaWarning ?] {
19+ export function getBodyString ( body : unknown , _logger : Logger = logger ) : [ string | undefined , NetworkMetaWarning ?] {
4320 try {
4421 if ( typeof body === 'string' ) {
4522 return [ body ] ;
@@ -50,23 +27,18 @@ export function getBodyString(
5027 }
5128
5229 if ( body instanceof FormData ) {
53- return [ _serializeFormData ( body ) ] ;
30+ return [ serializeFormData ( body ) ] ;
5431 }
5532
5633 if ( ! body ) {
5734 return [ undefined ] ;
5835 }
5936 } catch ( error ) {
60- // RelayLogger
61- if ( DEBUG_BUILD && logger && 'exception' in logger ) {
62- logger . exception ( error , 'Failed to serialize body' , body ) ;
63- } else if ( DEBUG_BUILD && logger ) {
64- logger . error ( error , 'Failed to serialize body' , body ) ;
65- }
37+ DEBUG_BUILD && logger . error ( error , 'Failed to serialize body' , body ) ;
6638 return [ undefined , 'BODY_PARSE_ERROR' ] ;
6739 }
6840
69- DEBUG_BUILD && logger ? .info ( 'Skipping network body because of body type' , body ) ;
41+ DEBUG_BUILD && logger . info ( 'Skipping network body because of body type' , body ) ;
7042
7143 return [ undefined , 'UNPARSEABLE_BODY_TYPE' ] ;
7244}
0 commit comments