From 5459f2a03144fb017eaa3842517db04308a49323 Mon Sep 17 00:00:00 2001
From: byrne-greg <5464272+byrne-greg@users.noreply.github.com>
Date: Fri, 8 May 2020 13:43:22 +0100
Subject: [PATCH 1/2] Adding HTTP status code to error.toJSON (axios#2947)
---
lib/core/enhanceError.js | 3 ++-
test/specs/core/createError.spec.js | 1 +
test/specs/core/enhanceError.spec.js | 12 +++++++++++-
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/lib/core/enhanceError.js b/lib/core/enhanceError.js
index b6bc4444e1..db04ec8ea0 100644
--- a/lib/core/enhanceError.js
+++ b/lib/core/enhanceError.js
@@ -35,7 +35,8 @@ module.exports = function enhanceError(error, config, code, request, response) {
stack: this.stack,
// Axios
config: this.config,
- code: this.code
+ code: this.code,
+ status: this.response && this.response.status ? this.response.status : null
};
};
return error;
diff --git a/test/specs/core/createError.spec.js b/test/specs/core/createError.spec.js
index 53f708badd..7b1f6c699c 100644
--- a/test/specs/core/createError.spec.js
+++ b/test/specs/core/createError.spec.js
@@ -23,6 +23,7 @@ describe('core::createError', function() {
expect(json.message).toBe('Boom!');
expect(json.config).toEqual({ foo: 'bar' });
expect(json.code).toBe('ESOMETHING');
+ expect(json.status).toBe(200);
expect(json.request).toBe(undefined);
expect(json.response).toBe(undefined);
});
diff --git a/test/specs/core/enhanceError.spec.js b/test/specs/core/enhanceError.spec.js
index f8e24d108e..767ebfdde7 100644
--- a/test/specs/core/enhanceError.spec.js
+++ b/test/specs/core/enhanceError.spec.js
@@ -1,7 +1,7 @@
var enhanceError = require('../../../lib/core/enhanceError');
describe('core::enhanceError', function() {
- it('should add config, config, request and response to error', function() {
+ it('should add config, code, request, response, and toJSON function to error', function() {
var error = new Error('Boom!');
var request = { path: '/foo' };
var response = { status: 200, data: { foo: 'bar' } };
@@ -11,9 +11,19 @@ describe('core::enhanceError', function() {
expect(error.code).toBe('ESOMETHING');
expect(error.request).toBe(request);
expect(error.response).toBe(response);
+ expect(typeof error.toJSON).toBe('function');
expect(error.isAxiosError).toBe(true);
});
+ it('should serialize to JSON with a status of null when there is no response', function() {
+ var error = new Error('Boom!');
+ var request = { path: '/foo' };
+ var response = undefined;
+
+ var errorAsJson = enhanceError(error, { foo: 'bar' }, 'ESOMETHING', request, response).toJSON();
+ expect(errorAsJson.status).toEqual(null);
+ });
+
it('should return error', function() {
var error = new Error('Boom!');
expect(enhanceError(error, { foo: 'bar' }, 'ESOMETHING')).toBe(error);
From 1c76dfac297ccfcdd762ff91ae9f124aef8ad964 Mon Sep 17 00:00:00 2001
From: byrne-greg <5464272+byrne-greg@users.noreply.github.com>
Date: Fri, 8 May 2020 13:43:54 +0100
Subject: [PATCH 2/2] Adding Error display div to internal server client.html
---
sandbox/client.html | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/sandbox/client.html b/sandbox/client.html
index 55051c2ea0..c06ae16940 100644
--- a/sandbox/client.html
+++ b/sandbox/client.html
@@ -5,7 +5,6 @@