1
1
import colorize from "./util/colorize"
2
2
import { MiddlewareStack } from "./middleware-stack"
3
- import { ILogger , logger as defaultLogger } from "./logger"
3
+ import { ILogger } from "./logger"
4
4
import { JsonapiResponseDoc , JsonapiRequestDoc } from "./jsonapi-spec"
5
5
6
6
export type RequestVerbs = keyof Request
@@ -60,6 +60,10 @@ export class Request {
60
60
this . logger . debug ( colorize ( "bold" , JSON . stringify ( responseJSON , null , 4 ) ) )
61
61
}
62
62
63
+ private _logInvalidJSON ( response : Response ) : void {
64
+ this . logger . debug ( `Invalid Response JSON: ${ response . clone ( ) . text ( ) } ` )
65
+ }
66
+
63
67
private async _fetchWithLogging (
64
68
url : string ,
65
69
options : RequestInit
@@ -111,9 +115,7 @@ export class Request {
111
115
try {
112
116
json = await response . clone ( ) . json ( )
113
117
} catch ( e ) {
114
- if ( response . body ) {
115
- this . logger . debug ( `Invalid Response JSON: ${ response . text ( ) } ` )
116
- }
118
+ this . _logInvalidJSON ( response )
117
119
118
120
throw new ResponseError ( response , `invalid json: ${ json } ` , e )
119
121
}
@@ -137,6 +139,7 @@ export class Request {
137
139
throw new ResponseError ( response , "record not found" )
138
140
} else {
139
141
// Bad JSON, for instance an errors payload
142
+ this . _logInvalidJSON ( response )
140
143
throw new ResponseError ( response , "invalid json" )
141
144
}
142
145
}
0 commit comments