0

I have button on click it make request access to api For the first time it succeeds but second time it fails The parameter PromiseStatus in first time pending, and in second time this parameter worth resolved.

This code in my service:

function commandEndInstallation() {
const requestOptions = {
    method: 'POST',
    headers:{ 'Content-Type': 'application/json' }
};

return fetch(`${config.apiUrl}/Commands/PostCommandEndInstallation`, requestOptions).then(handleResponse);}


function handleResponse(response) {
return response.text().then(text => {
    const data = text && JSON.parse(text);
    if (!response.ok) {
        if (response.status === 401) {
            location.reload(true);
        }
        const error = (data && data.Message) || response.statusText;
        return Promise.reject(error);
    }

    return data;
});}
Nir Amir
  • 120
  • 1
  • 14
  • 1
    You need to show us what you're doing. It seems like you're trying to check the promise returned from a single call multiple times: remember that promises can only be resolved once. – Terry Mar 29 '20 at 11:28
  • Take a look at [How to reject a promise from inside then function](https://stackoverflow.com/questions/21260602/how-to-reject-a-promise-from-inside-then-function). Returning `Promise.reject(error);` returns another promise. – Shoejep Apr 10 '20 at 06:19

0 Answers0