Skip to content

Commit

Permalink
Merge pull request #3558 from tchak/fix-json-api-errors-pointer-spec
Browse files Browse the repository at this point in the history
[BUGFIX release] Follow JSON-API error object spec
  • Loading branch information
fivetanley committed Jul 18, 2015
2 parents 0be4bd3 + 33c6744 commit 21ebe9b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/ember-data/lib/adapters/errors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const EmberError = Ember.Error;

const SOURCE_POINTER_REGEXP = /data\/(attributes|relationships)\/(.*)/;
const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;

/**
@class AdapterError
Expand Down Expand Up @@ -122,7 +122,7 @@ export function errorsHashToArray(errors) {
title: 'Invalid Attribute',
detail: messages[i],
source: {
pointer: `data/attributes/${key}`
pointer: `/data/attributes/${key}`
}
});
}
Expand Down
18 changes: 14 additions & 4 deletions packages/ember-data/tests/unit/adapter-errors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ var errorsArray = [
{
title: 'Invalid Attribute',
detail: 'is invalid',
source: { pointer: 'data/attributes/name' }
source: { pointer: '/data/attributes/name' }
},
{
title: 'Invalid Attribute',
detail: 'must be a string',
source: { pointer: 'data/attributes/name' }
source: { pointer: '/data/attributes/name' }
},
{
title: 'Invalid Attribute',
detail: 'must be a number',
source: { pointer: 'data/attributes/age' }
source: { pointer: '/data/attributes/age' }
}
];

Expand All @@ -57,6 +57,16 @@ test("errorsArrayToHash", function() {
deepEqual(result, errorsHash);
});

test("errorsArrayToHash without trailing slash", function() {
var result = DS.errorsArrayToHash([
{
detail: 'error message',
source: { pointer: 'data/attributes/name' }
}
]);
deepEqual(result, { name: ['error message'] });
});

test("DS.InvalidError will normalize errors hash with deprecation", function() {
var error;

Expand All @@ -68,7 +78,7 @@ test("DS.InvalidError will normalize errors hash with deprecation", function() {
{
title: 'Invalid Attribute',
detail: 'is invalid',
source: { pointer: 'data/attributes/name' }
source: { pointer: '/data/attributes/name' }
}
]);
});

0 comments on commit 21ebe9b

Please sign in to comment.