Browse Source

remove parse-json

Closes #134
http2
Vsevolod Strukchinsky 9 years ago
parent
commit
cc36bb214a
  1. 11
      index.js
  2. 1
      package.json

11
index.js

@ -17,7 +17,6 @@ const unzipResponse = require('unzip-response');
const createErrorClass = require('create-error-class'); const createErrorClass = require('create-error-class');
const nodeStatusCodes = require('node-status-codes'); const nodeStatusCodes = require('node-status-codes');
const isPlainObj = require('is-plain-obj'); const isPlainObj = require('is-plain-obj');
const parseJson = require('parse-json');
function requestAsEventEmitter(opts) { function requestAsEventEmitter(opts) {
opts = opts || {}; opts = opts || {};
@ -103,10 +102,9 @@ function asCallback(opts, cb) {
if (opts.json && statusCode !== 204) { if (opts.json && statusCode !== 204) {
try { try {
data = parseJson(data); data = JSON.parse(data);
} catch (e) { } catch (e) {
e.fileName = urlLib.format(opts); err = new got.ParseError(e, opts, data);
err = new got.ParseError(e, opts);
} }
} }
@ -346,7 +344,10 @@ function stdError(error, opts) {
got.RequestError = createErrorClass('RequestError', stdError); got.RequestError = createErrorClass('RequestError', stdError);
got.ReadError = createErrorClass('ReadError', 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) { got.HTTPError = createErrorClass('HTTPError', function (statusCode, opts) {
stdError.call(this, {}, opts); stdError.call(this, {}, opts);

1
package.json

@ -54,7 +54,6 @@
"lowercase-keys": "^1.0.0", "lowercase-keys": "^1.0.0",
"node-status-codes": "^1.0.0", "node-status-codes": "^1.0.0",
"object-assign": "^4.0.1", "object-assign": "^4.0.1",
"parse-json": "^2.1.0",
"timed-out": "^2.0.0", "timed-out": "^2.0.0",
"unzip-response": "^1.0.0", "unzip-response": "^1.0.0",
"url-parse-lax": "^1.0.0" "url-parse-lax": "^1.0.0"

Loading…
Cancel
Save