Repository: sindresorhus/got (ts)

Issue:
ParseError should contain err.statusCode
`curl -v https://api.github.com/repos/震动/generator-test` should output a json but it does print an HTML pages, which gives a `ParseError` if we use `got()` with `options.json=true`. Though, I was expecting that the ParseError contained the `err.statusCode` property, which doesn't at the moment. It has to be accessed via `err.response.statusCode` which kind sucks :(

Thoughts?

Pull request:
Add statusCode to ParseError, closes #182.
Let me know if everything is as expected.

Patch:
diff --git a/index.js b/index.js
index 1a4d91d..0ee457e 100644
--- a/index.js
+++ b/index.js
@@ -105,7 +105,7 @@ function asPromise(opts) {
 						try {
 							res.body = JSON.parse(res.body);
 						} catch (e) {
-							throw new got.ParseError(e, opts, data);
+							throw new got.ParseError(e, statusCode, opts, data);
 						}
 					}
 
@@ -318,8 +318,10 @@ function stdError(error, opts) {
 
 got.RequestError = createErrorClass('RequestError', stdError);
 got.ReadError = createErrorClass('ReadError', stdError);
-got.ParseError = createErrorClass('ParseError', function (e, opts, data) {
+got.ParseError = createErrorClass('ParseError', function (e, statusCode, opts, data) {
 	stdError.call(this, e, opts);
+	this.statusCode = statusCode;
+	this.statusMessage = nodeStatusCodes[this.statusCode];
 	this.message = `${e.message} in "${urlLib.format(opts)}": \n${data.slice(0, 77)}...`;
 });
 


Test patch:
diff --git a/test/json.js b/test/json.js
index 3266714..617bc12 100644
--- a/test/json.js
+++ b/test/json.js
@@ -73,6 +73,15 @@ test('catches errors on invalid non-200 responses', async t => {
 	}
 });
 
+test('should have statusCode in err', async t => {
+	try {
+		await got(`${s.url}/non200-invalid`, {json: true});
+		t.fail('Exception was not thrown');
+	} catch (err) {
+		t.is(err.statusCode, 500);
+	}
+});
+
 test.after('cleanup', async () => {
 	await s.close();
 });