Skip to content

Commit

Permalink
Add homepage data to rejection when not parseable
Browse files Browse the repository at this point in the history
  • Loading branch information
Davies, Brendan committed Dec 19, 2018
1 parent 0d24817 commit c6cc22b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/hyperGard.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,14 @@ var
return isObject(data) ? {
data: new Resource(endpoint, data),
xhr: response
} : Promise.reject();
} : Promise.reject(data);
})
.catch(function() {
.catch(function(rejection) {
return Promise.reject({
data: rejection,
error: {
code: '0002',
msg: 'Could not parse homepage'
msg: 'Could not parse homepage',
},
xhr: response
});
Expand Down
3 changes: 3 additions & 0 deletions test/mocks/invalid-json.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
er-or
}
16 changes: 10 additions & 6 deletions test/spec/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ describe('hyperGard', function() {

it('should call reject promise with error object', function() {
expect(this.onError).toHaveBeenCalledWith({
data: [],
error: {
code: '0002',
msg: 'Could not parse homepage'
msg: 'Could not parse homepage',
},

xhr: this.testResponse
});
});
Expand All @@ -217,9 +217,10 @@ describe('hyperGard', function() {

it('should call reject promise with error object', function() {
expect(this.onError).toHaveBeenCalledWith({
data: true,
error: {
code: '0002',
msg: 'Could not parse homepage'
msg: 'Could not parse homepage',
},

xhr: this.testResponse
Expand Down Expand Up @@ -248,9 +249,10 @@ describe('hyperGard', function() {

it('should call reject promise with error object', function() {
expect(this.onError).toHaveBeenCalledWith({
data: false,
error: {
code: '0002',
msg: 'Could not parse homepage'
msg: 'Could not parse homepage',
},

xhr: this.testResponse
Expand Down Expand Up @@ -279,9 +281,10 @@ describe('hyperGard', function() {

it('should call reject promise with error object', function() {
expect(this.onError).toHaveBeenCalledWith({
data: 1,
error: {
code: '0002',
msg: 'Could not parse homepage'
msg: 'Could not parse homepage',
},

xhr: this.testResponse
Expand Down Expand Up @@ -310,9 +313,10 @@ describe('hyperGard', function() {

it('should call reject promise with error object', function() {
expect(this.onError).toHaveBeenCalledWith({
data: 'string',
error: {
code: '0002',
msg: 'Could not parse homepage'
msg: 'Could not parse homepage',
},

xhr: this.testResponse
Expand Down

0 comments on commit c6cc22b

Please sign in to comment.