提交redux-form的例外情况没有被记录,而是默默地被压制

时间:2016-10-14 00:03:24

标签: exception reactjs console.log redux-form

我有一个使用标准handleSubmit提交的redux表单。在我的submit()函数中,我得到了一些错误(由于我自己的逻辑),一个属性不存在。但是,此错误只是静默抑制,并且没有显示红色控制台日志,说明存在错误和其他信息。 Redux记录的简单显示了一个没有其他信息的动作redux-form/SET_SUBMIT_FAILED。如何在此方案中获取错误日志?

Console logs with first log line printed but nothing else after that

<MyButton
    onClick={this.props.handleSubmit(submit)}
>
    List Now
</MyButton>

提交功能

function submit(values) {
    console.log("Submit called")        // this gets logged

    const url = 'store/listing/';

    const options = {
        method: 'POST',
    }

    let formData = new FormData();

    const valuesAsJS = updatedValues.toJS()

    Object.keys(valuesAsJS).forEach(key =>formData.append(key, valuesAsJS[key]))

    let i
    for (i=0; i<valuesAsJS.images.length; i++){                 // error here as valuesAsJS.images is undefined
        formData.append('image[]', valuesAsJS.images[i])
    }

    // no more logs happen whatsover and the system freezes, with 
    console.log("Submitting form response for listing creation")


    return api_request({url, options, body: formData})
        .then(response=> {

            if (response.ok && response.status == 201) {


                console.log("Listing creation success")

            } else {
                // not created show error

                console.log("Erorr creating listing")
                throw new SubmissionError({code: "Please re-enter or try again later", _error: true})

            }
        })
}

0 个答案:

没有答案