fix: 🐛 tweak validation error schema to match API

This commit is contained in:
Randall Morey committed 2020-09-11 12:01:56 -04:00
1 parent 7fd316a400
commit a13e93ec55
7 files changed
+23 -23

No files matched your search

+2 -2
View File
@@ -235,7 +235,7 @@ export default class ApplicationAdapter extends RESTAdapter.extend(
* @return {object}
*/
transformValidationErrors(payload) {
const fieldErrors = get(payload, 'details.fields') || [];
const fieldErrors = get(payload, 'details.request_fields') || [];
// Normalize the primary error message into "base", which is an error
// that applies to the whole model instance
const baseError = {
@@ -247,7 +247,7 @@ export default class ApplicationAdapter extends RESTAdapter.extend(
};
// Normalize field-specific errors, if any.
const errors = fieldErrors.map((error) => ({
detail: error.message,
detail: error.description,
source: { pointer: `/data/attributes/${error.name}` },
}));
// Return a list of JSON API errors rooted under the `errors` key.
@@ -158,7 +158,7 @@ module('Unit | Adapter | application', function (hooks) {
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
fields: [{ name: 'name', message: 'Name is wrong.' }],
request_fields: [{ name: 'name', description: 'Name is wrong.' }],
},
};
const handledResponse = adapter.handleResponse(400, {}, payload);