Skip to content
Discussion options

You must be logged in to vote

I've done following to handle multiple errors from a api response:

function setMultipleErrors(field, errors) {
    const types = {}
    errors.forEach((error, i) => {
        types[`apiError${i + 1}`] = error
    })

    form.setError(field, {
        types,
    })
}

function handleApiErrors(apiErrors) {
    const newFormErrors = {}

    apiErrors.forEach(({ field, messages }) => {
        messages.forEach((message) => {
            if (field in form.getValues()) {
                if (!newFormErrors[field]) {
                    newFormErrors[field] = []
                }

                newFormErrors[field].push(message)
            } else {
                if (!newFormErrors.__general…

Replies: 2 comments 11 replies

Comment options

You must be logged in to vote
8 replies
@trickreich
Comment options

@trickreich
Comment options

@bluebill1049
Comment options

@bluebill1049
Comment options

@trickreich
Comment options

Comment options

You must be logged in to vote
3 replies
@bluebill1049
Comment options

@Moshyfawn
Comment options

@vairadurai007
Comment options

Answer selected by bluebill1049
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants