Skip to content

Commit

Permalink
fix(body): only use super.buffer()
Browse files Browse the repository at this point in the history
Only use super.buffer(), as super.json() and others may fail 
unexpectedly and unnecessarily.
  • Loading branch information
larsgw committed Aug 27, 2019
1 parent fe75247 commit 7558e7d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ class Request extends _fetch.Request {
}

arrayBuffer () {
super.arrayBuffer()
super.buffer()
const buf = this[_body]
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)
}

text () {
super.text()
super.buffer()
return this[_body].toString()
}

json () {
super.json()
super.buffer()
try {
return JSON.parse(this.text())
return JSON.parse(this[_body].toString())
} catch (err) {
throw new fetch.FetchError(`invalid json response body at ${this.url} reason: ${err.message}`, 'invalid-json')
}
Expand All @@ -120,18 +120,18 @@ class Response extends _fetch.Response {
}

arrayBuffer () {
super.arrayBuffer()
super.buffer()
const buf = this[_body]
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)
}

text () {
super.text()
super.buffer()
return this[_body].toString()
}

json () {
super.json()
super.buffer()
try {
return JSON.parse(this[_body].toString())
} catch (err) {
Expand Down

0 comments on commit 7558e7d

Please sign in to comment.