Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Expose status codes on error objects
Browse files Browse the repository at this point in the history
There may be cases where callers want access to the status code that caused the error (e.g. logging/metrics, or terse user-facing error messages), so this allows them to easily get at it.
  • Loading branch information
Ben Demboski authored and alexlafroscia committed Nov 30, 2017
1 parent c92d9a7 commit 25f4e55
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions addon/mixins/ajax-request.js
Expand Up @@ -551,6 +551,7 @@ export default Mixin.create({

error = new AjaxError(payload, detailedMessage);
}
error.status = status;

return error;
},
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/mixins/ajax-request-test.js
Expand Up @@ -570,6 +570,7 @@ describe('Unit | Mixin | ajax request', function() {
expect(result.message).to.contain('Some error response');
expect(result.message).to.contain('GET');
expect(result.message).to.contain('/posts');
expect(result.status).to.equal(408);
});
});

Expand All @@ -587,6 +588,7 @@ describe('Unit | Mixin | ajax request', function() {
expect(result.message).to.contain('Some error response');
expect(result.message).to.contain('GET');
expect(result.message).to.contain('/posts');
expect(result.status).to.equal(408);
});
});

Expand Down Expand Up @@ -883,6 +885,7 @@ describe('Unit | Mixin | ajax request', function() {
.catch(function(reason) {
expect(isTimeoutError(reason)).to.be.ok;
expect(reason.payload).to.be.null;
expect(reason.status).to.be.undefined;
});
});

Expand All @@ -901,6 +904,7 @@ describe('Unit | Mixin | ajax request', function() {
.catch(function(reason) {
expect(reason instanceof errorClass).to.be.ok;
expect(reason.payload).to.not.be.undefined;
expect(reason.status).to.equal(status);

const { errors } = reason.payload;

Expand Down

0 comments on commit 25f4e55

Please sign in to comment.