You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ASYNCTHUNK in RTK SLICE:
export const AnonymousSaveIssue = createAsyncThunk('AnonymousSaveIssue/POST', async (postData) => {
return new Promise(async (resolve, reject) => {
try {
const response = await http://request.post(${endpoints.issueEntry.anonymousSaveIssue}?businessChannelId=${PAGESTATE.BusinessChannelId}, postData);
if (response.status === 200) {
resolve(http://response.data);
} else {
reject({ status: response.status, message: 'HTTP response status is not 200.' });
}
} catch (error) {
console.log(error)
reject(error);
}
});
});
The text was updated successfully, but these errors were encountered:
fulutas
changed the title
In the API request created with RTK async thunk, success toast runs even though the HTTP request failed.
Toast Promise - In the API request created with RTK async thunk, success toast runs even though the HTTP request failed.
Nov 1, 2023
I use sonner toast in react projects with great pleasure. But there is a problem with using promises.
The code below runs success toast even though the HTTP request failed.
COMPONENT SUBMIT CODE:
toast.promise(dispatch(AnonymousSaveIssue(postData)).then(res => {
if (res.meta.requestStatus === "fulfilled") {
return navigate(
/issue-result/${res.payload.issueID}?BusinessChannelID=${PAGESTATE.BusinessChannelId}
, { state: { issueId: res.payload.issueID } })}
}), {
loading: 'Saving notification...',
success: (data) => {
return
Notification created successfully.
;},
error: 'Error',
});
ASYNCTHUNK in RTK SLICE:
export const AnonymousSaveIssue = createAsyncThunk('AnonymousSaveIssue/POST', async (postData) => {
return new Promise(async (resolve, reject) => {
try {
const response = await http://request.post(
${endpoints.issueEntry.anonymousSaveIssue}?businessChannelId=${PAGESTATE.BusinessChannelId}
, postData);if (response.status === 200) {
resolve(http://response.data);
} else {
reject({ status: response.status, message: 'HTTP response status is not 200.' });
}
} catch (error) {
console.log(error)
reject(error);
}
});
});
The text was updated successfully, but these errors were encountered: