Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Aug 17, 2022
1 parent 3f401ae commit d2045cb
Show file tree
Hide file tree
Showing 5 changed files with 781 additions and 848 deletions.
24 changes: 13 additions & 11 deletions lib/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const FetchError = require('./fetch-error.js')
let convert
try {
convert = require('encoding').convert
} catch (e) {}
} catch (e) {
// defer error until textConverted is called
}

const INTERNALS = Symbol('Body internals')
const CONSUME_BODY = Symbol('consumeBody')
Expand Down Expand Up @@ -69,16 +71,16 @@ class Body {
))
}

json () {
return this[CONSUME_BODY]().then(buf => {
try {
return JSON.parse(buf.toString())
} catch (er) {
return Promise.reject(new FetchError(
`invalid json response body at ${
this.url} reason: ${er.message}`, 'invalid-json'))
}
})
async json () {
try {
const buf = await this[CONSUME_BODY]()
return JSON.parse(buf.toString())
} catch (er) {
throw new FetchError(
`invalid json response body at ${this.url} reason: ${er.message}`,
'invalid-json'
)
}
}

text () {
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ class TestServer {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.setHeader('Content-Encoding', 'gzip')
// eslint-disable-next-line promise/catch-or-return
new zlib.Gzip().end('hello world').concat().then(buf => res.end(buf))
}

if (p === '/gzip-truncated') {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.setHeader('Content-Encoding', 'gzip')
// eslint-disable-next-line promise/catch-or-return
new zlib.Gzip().end('hello world').concat().then(buf =>
res.end(buf.slice(0, buf.length - 8)))
}
Expand All @@ -76,6 +78,7 @@ class TestServer {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.setHeader('Content-Encoding', 'deflate')
// eslint-disable-next-line promise/catch-or-return
new zlib.Deflate().end('hello world').concat().then(buf => res.end(buf))
}

Expand All @@ -96,6 +99,7 @@ class TestServer {
res.statusCode = 200
res.setHeader('Content-Type', 'text/plain')
res.setHeader('Content-Encoding', 'deflate')
// eslint-disable-next-line promise/catch-or-return
new zlib.DeflateRaw().end('hello world').concat().then(buf => res.end(buf))
}

Expand Down
Loading

0 comments on commit d2045cb

Please sign in to comment.