UNPKG

@instructure/quiz-interactions

Version:

A React UI component Library for quiz interaction types.

27 lines 763 B
/** * This function converts errors into a format that can be used by InstUI components. * * @param {string[] | import('@instructure/ui-form-field').FormFieldMessage} errors - The errors to normalize * @returns {import('@instructure/ui-form-field').FormFieldMessage[]} The normalized errors */ export function normalizeErrors(errors) { if (errors == null) { return []; } return errors.map(function (error) { if (typeof error === 'string') { return { text: error, type: 'newError' }; } if (error.type !== 'error' && error.type !== 'newError') { // This is a fallback for any other type of message return error; } return { text: error.text || '', type: 'newError' }; }); }