@@ -20,16 +20,15 @@ type Context = {
2020 start : number ;
2121} ;
2222
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 ;
3332
3433const configuration = z
3534 . object ( {
@@ -55,32 +54,30 @@ export function pre() {
5554 return ;
5655 }
5756
58- const domain =
59- ( userConfig ?. enableDomain ??
57+ const enableDomain =
58+ userConfig ?. enableDomain ??
6059 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 ;
6462
65- const url =
66- ( userConfig ?. enableUrl ??
63+ const enableUrl =
64+ userConfig ?. enableUrl ??
6765 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 ;
7168
72- const path =
73- ( userConfig ?. enablePath ??
69+ const enablePath =
70+ userConfig ?. enablePath ??
7471 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 ;
7875
7976 writeOutput < PluginOutput < Context > > ( {
8077 capture : {
81- ... domain ,
82- ... url ,
83- ... path ,
78+ domain,
79+ url,
80+ path,
8481 } ,
8582 context : {
8683 start : Date . now ( ) ,
@@ -107,7 +104,17 @@ export function post() {
107104
108105 let seenError : string | undefined ;
109106 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+ }
111118 }
112119
113120 const durationMs =
0 commit comments