Я учусь делать вызовы http из приложения узла / машинописи. У меня есть следующий метод, используя npm package
Ax ios, чтобы сделать http получить вызов к поддельной api конечной точке.
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";
}
Когда я запустить приведенный выше код, я вижу следующие консольные выходы, но нет консольного вывода ни из блока then
, ни из блока catch
. Я не понимаю, куда идет управление.
Вывод, который я вижу:
Entered the method.
nothing worked
Что я ожидаю увидеть:
Entered the method.
inside then //or inside catch
Может ли кто-нибудь помочь мне понять, что я я здесь не так делаю?