Browse Source

Only parse JSON on successfull requests

Onionoo returns HTML error pages for bad requests which chokes the JSON parser and means we throw a ParseError when we really want to throw an HTTPError
pull/14/head
Luke Childs 8 years ago
parent
commit
a29cde357c
  1. 3
      src/index.js

3
src/index.js

@ -72,7 +72,6 @@ class Onionoo {
// Returns a promise for a request
makeRequest (url) {
const options = {
json: true,
headers: {
'user-agent': `onionoo-node-client v${pkg.version} (${pkg.homepage})`
}
@ -84,7 +83,7 @@ class Onionoo {
statusCode: response.statusCode,
statusMessage: response.statusMessage,
headers: response.headers,
body: response.body
body: JSON.parse(response.body)
}
// Cache response

Loading…
Cancel
Save