2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

Adding HTTP status code to error.toJSON (#2956)

* Adding HTTP status code to error.toJSON (axios#2947)

* Adding Error display div to internal server client.html

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Greg Byrne
2021-09-05 12:45:24 +01:00
committed by GitHub
parent b5a1a67b3c
commit cd7ff042b0
4 changed files with 23 additions and 3 deletions
+1
View File
@@ -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);
});
+11 -1
View File
@@ -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);