I would like to return a new promise that has the data for both the success case and the error case.
you could use this way:
const async myfunction = (bodyData) { const totalData = await new Promise((dataSuccessReturn, errorReturn) => { axios({ method: 'POST', url: `${API}/users/user/`, // your address api url for example localHost:8000/users/user headers: { "Content-Type": "application/json" }, data: bodyData }) .then(res => { dataSuccessReturn(res.data) }) .catch(error => { errorReturn(error.response.data.message) }) }) return totalData }This will generate a total data with a success case and an error case if there is one.