const generalFormErrorKey = '_error'

function mapToFieldErrors(errorId, acceptedErrors) {
  return acceptedErrors.reduce((fieldErrors, acceptedError) => {
    if (acceptedError.id === errorId) {
      const errorKey = acceptedError.field || generalFormErrorKey
      return {
        [errorKey]: acceptedError.message,
        ...fieldErrors,
      }
    }
    return fieldErrors
  }, {})
}

export default function (errors, acceptedErrors) {
  if (errors instanceof Array) {
    return errors.reduce(
      (fieldErrors, error) => mapToFieldErrors(error.message, acceptedErrors),
      {},
    )
  }

  return mapToFieldErrors(errors, acceptedErrors)
}

@@ -84,16 +84,192 @@
 rors) %7B%0A
+  if (!acceptedErrors %7C%7C !acceptedErrors.find((%7B id %7D) =%3E id === errorId)) %7B%0A    return %7B %5BgeneralFormErrorKey%5D: 'An unknown error has occured. Please try again later.' %7D%0A  %7D%0A%0A
   return

Handle unexpected error