Humanize validation errors returned on registration

This commit is contained in:
raeno 2018-12-03 22:43:58 +04:00
parent 3fa9b39150
commit 822559afd8
3 changed files with 22 additions and 6 deletions

12
src/modules/errors.js Normal file
View file

@ -0,0 +1,12 @@
import {capitalize, reduce} from 'lodash'
export function humanizeErrors (errors) {
return reduce(errors, (errs, val, k) => {
let message = reduce(val, (acc, message) => {
let key = capitalize(k.replace(/_/g, ' '))
return acc + [key, message].join(' ') + '. '
}, '')
return [...errs, message]
}, [])
}