aboutsummaryrefslogtreecommitdiff
path: root/src/modules/errors.js
blob: 25b5bd81e568ef7a56bf46299da5a039b24b6d0c (plain)
1
2
3
4
5
6
7
8
9
10
11
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]
  }, [])
}