fetchival icon indicating copy to clipboard operation
fetchival copied to clipboard

get body on 400 error

Open roccomuso opened this issue 6 years ago • 1 comments

How to get json body from a code 400 server response? I can see only the body: PassThrough { ... } stream. Aren't chunks collected and json parsed?

roccomuso avatar Dec 19 '18 23:12 roccomuso

Right now I'm doing concat myself.

function concatStream(stream) {
  return new Promise((resolve, reject) => {
    let result = ''
    stream.on('data', (chunk) => {
      result += chunk.toString()
    })
    stream.on('end', () => {
      resolve(JSON.parse(result))
    })
    stream.on('error', (err) => reject(err))
  })
}

roccomuso avatar Jan 16 '19 11:01 roccomuso