相关疑难解决方法(0)

如何从 javascript 错误对象读取错误消息

有人可以帮我解决以下问题吗:-)

我正在通过 redux 操作进行后调用,如下所示。

export const addEmployee = ({ firstName, surname, contactNumber, email }) => async dispatch => {
const payloadBody = JSON.stringify({ firstName, surname, contactNumber, email });
    fetch('/api/users', { 
            method: 'POST', 
            body: payloadBody,
            headers: {
                'Content-Type': 'application/json'
            }
        })
        .then(response => {
            if (!response.ok) {
                return response.text()
                .then(text => { 
                    throw Error(text)
                });
            } else {
                dispatch(setAlert("New Employee added ", 'danger'));
            }
        })
        .catch(error => {
            console.log('>>> in CATCH block, error is =>', error);
            console.log('>>> in CATCH block, error …
Run Code Online (Sandbox Code Playgroud)

javascript

19
推荐指数
1
解决办法
5万
查看次数

标签 统计

javascript ×1