Function
errorsHashToArray (errors) Array public deprecated
Module:
@ember-data/adapter/error
Defined in ../packages/adapter/addon/error.js:356
- errors
- Object
- hash with errors as properties
- returns
- Array
- array of errors in JSON-API format
Convert an hash of errors into an array with errors in JSON-API format.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import { errorsHashToArray } from '@ember-data/adapter/error'; let errors = { base: 'Invalid attributes on saving this record', name: 'Must be present', age: ['Must be present', 'Must be a number'] }; let errorsArray = errorsHashToArray(errors); // [ // { // title: "Invalid Document", // detail: "Invalid attributes on saving this record", // source: { pointer: "/data" } // }, // { // title: "Invalid Attribute", // detail: "Must be present", // source: { pointer: "/data/attributes/name" } // }, // { // title: "Invalid Attribute", // detail: "Must be present", // source: { pointer: "/data/attributes/age" } // }, // { // title: "Invalid Attribute", // detail: "Must be a number", // source: { pointer: "/data/attributes/age" } // } // ] |