我有一个React组件.在该组件中,我有一个函数onFormSubmit来自另一个组件调用函数.这个其他函数正在使用axios发出POST请求. 如果POST请求是真的,如果没有,我想返回对第一个函数或错误的响应.现在发生的是我的’SUCCESS RESPONSE’console.log总是触发,即使那时在axios POST请求中也有错误.如果有错误,那么应该触发’ERROR RESPONSE’console.log.
从第一部分
onFormSubmit = () => {
postJobDescriptionQuickApply(this.state, this.props.jobDescription.id)
.then((response) => {
console.log('SUCCESS RESPONSE', response)
})
.catch((error) => {
console.log('ERROR RESPONSE', error)
})
}
从第二部分
export const postJobDescriptionQuickApply = (easyApplyData, jobId) => apiUrl('easyApply', 'easyApply').then(url => axios
.post(url, {
applicant: {
email: easyApplyData.email,
fullName: `${easyApplyData.firstName} ${easyApplyData.lastName}`,
phoneNumber: easyApplyData.phoneNumber,
resume: easyApplyData.resume,
source: easyApplyData.source,
},
job: {
jobId,
},
})
.then((response) => {
console.log('SUCCESS', response.data.developerMessage)
return response.data.developerMessage
})
.catch((error) => {
// handle error
console.log('ERROR JOB DESCRIPTION', error.response.data.developerMessage)
return error.response.data.developerMessage
})