@@ -20,16 +20,15 @@ type Context = {
20
20
start : number ;
21
21
} ;
22
22
23
- type AnyResponse =
24
- | undefined
25
- | string
26
- | {
27
- error ?: string ;
28
- message ?: string ;
29
- err ?: {
30
- type ?: string ;
31
- } ;
32
- } ;
23
+ type AnyJsonResponse = {
24
+ error ?: string ;
25
+ message ?: string ;
26
+ err ?: {
27
+ type ?: string ;
28
+ } ;
29
+ } ;
30
+
31
+ type AnyResponse = undefined | string | AnyJsonResponse ;
33
32
34
33
const configuration = z
35
34
. object ( {
@@ -55,32 +54,30 @@ export function pre() {
55
54
return ;
56
55
}
57
56
58
- const domain =
59
- ( userConfig ?. enableDomain ??
57
+ const enableDomain =
58
+ userConfig ?. enableDomain ??
60
59
manifest . fields . find ( ( f ) => f . name === "enableDomain" ) ?. default ??
61
- true )
62
- ? { domain : input . request . domain }
63
- : { } ;
60
+ true ;
61
+ const domain = enableDomain ? input . request . domain : undefined ;
64
62
65
- const url =
66
- ( userConfig ?. enableUrl ??
63
+ const enableUrl =
64
+ userConfig ?. enableUrl ??
67
65
manifest . fields . find ( ( f ) => f . name === "enableUrl" ) ?. default ??
68
- true )
69
- ? { url : input . request . url }
70
- : { } ;
66
+ true ;
67
+ const url = enableUrl ? input . request . url : undefined ;
71
68
72
- const path =
73
- ( userConfig ?. enablePath ??
69
+ const enablePath =
70
+ userConfig ?. enablePath ??
74
71
manifest . fields . find ( ( f ) => f . name === "enablePath" ) ?. default ??
75
- true )
76
- ? { path : input . request . path }
77
- : { } ;
72
+ true ;
73
+
74
+ const path = enablePath ? input . request . path : undefined ;
78
75
79
76
writeOutput < PluginOutput < Context > > ( {
80
77
capture : {
81
- ... domain ,
82
- ... url ,
83
- ... path ,
78
+ domain,
79
+ url,
80
+ path,
84
81
} ,
85
82
context : {
86
83
start : Date . now ( ) ,
@@ -107,7 +104,17 @@ export function post() {
107
104
108
105
let seenError : string | undefined ;
109
106
if ( input . response ?. status && input . response . status >= 400 ) {
110
- seenError = body ?. error ?? body ?. message ?? body ?. err ?. type ;
107
+ if ( typeof body === "string" ) {
108
+ try {
109
+ const parsedBody = JSON . parse ( body ) as AnyJsonResponse ;
110
+ seenError =
111
+ parsedBody . error ?? parsedBody . message ?? parsedBody . err ?. type ;
112
+ } catch {
113
+ // noop, the body wasn't JSON
114
+ }
115
+ } else if ( typeof body === "object" && body !== null ) {
116
+ seenError = body ?. error ?? body ?. message ?? body ?. err ?. type ;
117
+ }
111
118
}
112
119
113
120
const durationMs =
0 commit comments