Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Follow JSON-API error object spec #3558

Merged
merged 1 commit into from
Jul 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' }
}
]);
});