question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

throw new SubmissionError() causing Uncaught (in promise) error.

See original GitHub issue

Hello! I am using Redux Thunk and React Form to do submission validations against my signup form. I want the errors returned by my API endpoint to appear inline in my form. Hence why I need SubmissionError. Everything works great without throwing a new submission error, the form does exactly what I need it to do. The problem is, when I put in the single line to throw new SubmissionError() I get the following error:

image

Here is my Action creator (using Redux Thunk):

import axios from 'axios';
import { browserHistory } from 'react-router';
import { CTAButtonUnload } from '../../buttons/CTAButton/CTAButtonUnload'
import { SubmissionError } from 'redux-form'

const ROOT_URL = 'XXXXXXXXXXXXXX';

export const signupUser = (formData) => {
    return function(dispatch) {
        axios.post(ROOT_URL + '/v1/user', {
                firstName: formData.firstName,
                lastName: formData.lastName,
                email: formData.email,
                password: formData.password
            })
            .then(response => {
                dispatch({
                    type: 'CTAButtonUnload',
                    payload: {
                        hover: false,
                        click: false,
                        loading: false
                    }
                })
                browserHistory.push('/signup/workspace');
            })
            .catch(response => {
                if(response.response.data.code == 403){
                    throw new SubmissionError({email: null, _error: response.response.data.description})
                }
                dispatch({
                    type: 'CTAButtonUnload',
                    payload: {
                        hover: false,
                        click: false,
                        loading: false
                    }
                })
            });
    }
}

Could this error be caused by a promise inside of SubmissionError()? I saw that others have had similar problems with this error, but they look to be using the Async validation option, I am not, so I am wondering if I am doing something wrong or if this is something with reduxForm?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:21
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

127reactions
sioquimcommented, Jan 25, 2017

I encountered a similar problem and managed to fix this by adding a return on the submit handler.

from

handleSignup = (data) => {
        this.props.actions.signup(data).then((result) => {
            ...
        }).catch((error) => {
            if (error.data.status === 'XXXXXX') {
                throw new SubmissionError({
                    email: 'This email is already registered'
                })
            }
        })
    }

to

handleSignup = (data) => {
        return this.props.actions.signup(data).then((result) => {
            ...
        }).catch((error) => {
            if (error.data.status === 'XXXXXX') {
                throw new SubmissionError({
                    email: 'This email is already registered'
                })
            }
        })
    }

I’m calling handleSignup() from my redux form component:

<SignupForm onSubmit={this.handleSignup} />
23reactions
aq1018commented, Apr 3, 2017

I had some progress on this one. As it turned out, I was using redux-form/immutable all over my code, except when importing SubmissionForm, I did:

import { SubmissionForm } from 'redux-form';

But if you are using redux-form/immutable, you need to use:

import { SubmissionForm } from 'redux-form/immutable';

Apparently they are two different classes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Throwing a SubmissionError of redux-form causes ...
Redux Form is expecting the error to come as the error in a rejected promise. Try this: export const searchPermissions = () =>...
Read more >
Throwing a SubmissionError of redux-form causes Uncaught ...
Redux Form is expecting the error to come as the error in a rejected promise. Try this: export const searchPermissions = () =>...
Read more >
SubmissionError
A throwable error that is used to return submit validation errors from onSubmit . The purpose being to distinguish promise rejection because of...
Read more >
uncaught error: objects are not valid as a react child (found
renderPosts() will return a Promise not the actual data, and AFAIK Reactjs will not resolve Promises implicitly in render . You need to...
Read more >
Error handling with promises
This happens for all errors, not just those caused by the throw statement. For example, a programming error: new Promise((resolve, reject) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found