11import colorize from "./util/colorize"
22import { MiddlewareStack } from "./middleware-stack"
3- import { ILogger , logger as defaultLogger } from "./logger"
3+ import { ILogger } from "./logger"
44import { JsonapiResponseDoc , JsonapiRequestDoc } from "./jsonapi-spec"
55
66export type RequestVerbs = keyof Request
@@ -60,6 +60,10 @@ export class Request {
6060 this . logger . debug ( colorize ( "bold" , JSON . stringify ( responseJSON , null , 4 ) ) )
6161 }
6262
63+ private _logInvalidJSON ( response : Response ) : void {
64+ this . logger . debug ( `Invalid Response JSON: ${ response . clone ( ) . text ( ) } ` )
65+ }
66+
6367 private async _fetchWithLogging (
6468 url : string ,
6569 options : RequestInit
@@ -111,9 +115,7 @@ export class Request {
111115 try {
112116 json = await response . clone ( ) . json ( )
113117 } catch ( e ) {
114- if ( response . body ) {
115- this . logger . debug ( `Invalid Response JSON: ${ response . text ( ) } ` )
116- }
118+ this . _logInvalidJSON ( response )
117119
118120 throw new ResponseError ( response , `invalid json: ${ json } ` , e )
119121 }
@@ -137,6 +139,7 @@ export class Request {
137139 throw new ResponseError ( response , "record not found" )
138140 } else {
139141 // Bad JSON, for instance an errors payload
142+ this . _logInvalidJSON ( response )
140143 throw new ResponseError ( response , "invalid json" )
141144 }
142145 }
0 commit comments