I am learning to do http calls from node/typescript application. I have the following method, using npm package Axios to do a http get call to a fake api end point.
public GetTrailById(trailId: number) : string {
console.log("Entered the method.");
const res = axios.get("https://reqres.in/api/users?page=2")
.then((res: { data: any; }) => {
console.log("inside then");
return "this is good, got response";
})
.catch((err: { response: any; }) => {
console.log("inside catch");
return "this is not good, inner catch";
});
console.log("nothing worked");
return "nothing worked";
}
When I run the above code, I do see the following console outputs, but no console output from either the then block or the catch block. I dont understand where the control goes.
Output I see:
Entered the method.
nothing worked
What I expect to see:
Entered the method.
inside then //or inside catch
Can someone help me figure out what I am doing wrong here?