Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1609

Promise.allSettled returning status as "fulfilled" even though API call is failed and showing status as 404

$
0
0

I have a Promise.allSettled which takes two API. Even though the second API is failed and returned 404 the promise status shows 'fulfilled'.

  async function loadLivePrerequisites() {    try {      const API_ENDPOINTS = getRequiredApis()      // [0] -> join link, [1] -> user name      const response = await Promise.allSettled(API_ENDPOINTS);      const joinLink = response[0].status === "fulfilled" ? response[0].value.data : undefined      setLiveDetails(joinLink)      let userName: string;      if(response[1].status === "fulfilled") {        userName = response[1].value.data.name      } else {        userName = userNameGenerator(user.firstName, user.lastName)      }      setUserName(userName)    } catch(error) {       console.log(error)    }  }

response:screenshot

network error (404):screenshot

I was expecting the status would be "rejected" and code inside the if statement would not be executed. Not sure if it is something wrong from my end or my lack of knowledge on how promise.allSettled work. Any help would be appreciated. Thank you in advance.


Viewing all articles
Browse latest Browse all 1609

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>