Kido
Kido
TTCTheo's Typesafe Cult
Created by Kido on 1/23/2024 in #questions
promise catch() and then() priority issue
even tho promise is asynchronous still it works in order by the code , but my code under works bit differently const exampleB = new Promise((res, rej) => rej('rej')) .then(res => console.log(res)) .catch(res => console.log(res)); // exampleB const exampleA = new Promise(res => res('res')).then(res => console.log(res)); // console res rej since exampleB's rejected right away it should register catch to the webapi and then example A's then () but when i check chrome deb tool, and source tab example A's then run earlier than example B's catch can someone plz explain this behavior? i dont understand since then from Promise B's shouldnt run since its rejected so its really about the chained code that matters here
2 replies
TTCTheo's Typesafe Cult
Created by Kido on 1/11/2024 in #questions
CORS while fetching data from api
i'm trying to fetch a data from geoDataSource. since i need to translate latitude and longitude into a city name. i got the api key and i try to fetch and the from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. this error comes. i tried mode: no-cors it didnt work but only gave me status 0. the problem here is it says CORS is from browser, and it is for security reason. so basically what i read says blocks the request from another domain if its not configured inside the server file or only the same domain can access to the server. so in order to access my domain has to be configured inside the domain or else i cant access the server! then why on earth the api website doesnt require my domain? and im currently just using live server inside the vscode , does it mean that i cant fetch api data since im requesting from local host? and i dont understnad why chrome blocks the localhost in the first place.
3 replies