diff --git a/index.js b/index.js index 56f2bdd12..213ab600f 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,6 @@ const unzipResponse = require('unzip-response'); const createErrorClass = require('create-error-class'); const nodeStatusCodes = require('node-status-codes'); const isPlainObj = require('is-plain-obj'); -const parseJson = require('parse-json'); function requestAsEventEmitter(opts) { opts = opts || {}; @@ -103,10 +102,9 @@ function asCallback(opts, cb) { if (opts.json && statusCode !== 204) { try { - data = parseJson(data); + data = JSON.parse(data); } catch (e) { - e.fileName = urlLib.format(opts); - err = new got.ParseError(e, opts); + err = new got.ParseError(e, opts, data); } } @@ -346,7 +344,10 @@ function stdError(error, opts) { got.RequestError = createErrorClass('RequestError', stdError); got.ReadError = createErrorClass('ReadError', stdError); -got.ParseError = createErrorClass('ParseError', stdError); +got.ParseError = createErrorClass('ParseError', function (e, opts, data) { + stdError.call(this, e, opts); + this.message = `${e.message} in "${urlLib.format(opts)}": \n${data.slice(0, 77)}...`; +}); got.HTTPError = createErrorClass('HTTPError', function (statusCode, opts) { stdError.call(this, {}, opts); diff --git a/package.json b/package.json index 58d2613c3..78a95dcfc 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,6 @@ "lowercase-keys": "^1.0.0", "node-status-codes": "^1.0.0", "object-assign": "^4.0.1", - "parse-json": "^2.1.0", "timed-out": "^2.0.0", "unzip-response": "^1.0.0", "url-parse-lax": "^1.0.0"