active-model-adapter
Version:
Adapters and Serializers for Rails's ActiveModel::Serializers
52 lines • 1.47 kB
TypeScript
import type { AnyObject } from './index.ts';
interface ErrorObject {
title: string;
detail: string;
source: {
pointer: string;
};
}
/**
* Convert an hash of errors into an array with errors in JSON-API format.
*
* ```javascript
* 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" }
* // }
* // ]
* ```
* @method errorsHashToArray
* @for @ember-data/adapter/error
* @static
* @param errors hash with errors as properties
* @return array of errors in JSON-API format
*/
export default function errorsHashToArray(errors: AnyObject): ErrorObject[];
export {};
//# sourceMappingURL=errors-hash-to-array.d.ts.map