CentraResponse.js 435 B

1234567891011121314151617181920212223
  1. module.exports = class CentraResponse {
  2. constructor (res, resOptions) {
  3. this.coreRes = res
  4. this.resOptions = resOptions
  5. this.body = Buffer.alloc(0)
  6. this.headers = res.headers
  7. this.statusCode = res.statusCode
  8. }
  9. _addChunk (chunk) {
  10. this.body = Buffer.concat([this.body, chunk])
  11. }
  12. async json () {
  13. return this.statusCode === 204 ? null : JSON.parse(this.body)
  14. }
  15. async text () {
  16. return this.body.toString()
  17. }
  18. }