AxiosError: connect ECONNREFUSED 127.0.0.1:80
I have a nodejs application and I have a axios inside it, because I need to call a api to populate the response of my api, but when I deployed my application, I'm getting this error from axios, someone know what is it?
49 Replies
Project ID:
N/A
You might find these helpful:
- Code Runs on Localhost but Uncaught Syntax Error After Deployment
- 404 Error
⚠️ experimental feature
This could be a lot of things, could I see a repo please?
N/A
It's private, but I can send the Axios call:
const request = axios.create({
baseURL,
timeout: 10000, // 10s timeout
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
});
I'm only getting request and using axios normally
What's the baseURL set to
the url of the api I want to call
and that is?
https://apiloterias.com.br/app
export default class LotteryApi {
getLottery = async (lottery) => {
try {
const { data } = await request.get('/resultado', {
params: {
loteria: lottery
}
});
return data;
} catch (error) {
console.error(error);
}
};
}
this way I call the endpoint I want and return the data
it would significantly help if i could see the repo
Why??? it's only this I send you, there is nothing more
it's only the call
I only call: lotteryApi.getLottery(...)
its not much to go off of
show me a screenshot of the error?
ok
No, in localhost works fine
try with the correct syntax
It's not this, I change the Promise I have and worked, I don't know what the error is in Axios, but when I redeploy worked, the axios is right, this headers is custom there is no problem with my axios call, but thank you so much
okay so it was a code issue either way
glad its working now!
Yes, is something about the Promise, in the catch of the Promise I wasn't using the res.status...
mmm mixing await with promises yummy
wrapped in a big try / catch block
await is a keyword that resolved promises though .then .catch is not good though
Finn you know what I mean
i do
and here are some links around handling promises if you want @Lucas Lima
https://www.youtube.com/watch?v=ITogH7lJTyE
https://trytm.vercel.app/
not work
the promises is to the map await until end to then return
if I do without promises
the array is send empty
can you paste the code i can format it so it works
(discord formatting so it will be slightly ugly looking )
( i asume the issue is your resolving the promises then trying to send a request back, but the request is closed )
try {
const lotteriesArray = [];
const promises = lotteries.map(async (lottery, index) => {
const response = await lotteryApi.getLottery(lottery);
lotteriesArray[index] = {
lottery_name: response.nome,
amount: response.valor_estimado_proximo_concurso,
color: lotteryColors[index],
date: response.data_concurso,
tender_number: response.numero_concurso,
description: lotteryDescription[index]
};
});
Promise.all(promises).then(() => {
res.status(200).json({
status: 200,
lotteries: lotteriesArray
});
}).catch(error => {
res.status(500).json({
error: "Server error, please try again later."
});
});
} catch (error) {
res.status(500).json({
error: "Server error, please try again later."
});
}
the all code
somthing like that?
oh wait
1 sec
that worke @Lucas Lima
i must admit ive never used promise.all
isn't there a way to do error handling without encapsulating everything in a try block?
ya
Example, because I would like to know too
using or the like
( altho i would not have that last line ) fixed
That's still try catch, or is that just the extent of JavaScript's error handling?
nah the idea is you wrap the function that throws with
to
and yes this is the extent.
like
error handling in ts is BADHey that look like Go
p much. and thats my goto solution
I like that example
which example
The one that looks like Go
this?
^
@Lucas Lima let us know if it worked or not when you are back
ah yea that
I will yoink for later use, thank you
nw. make sure you use zod aswell!
I don't do typescript
oh and it requires ts 4.6 > to get the inference union working properly
Typescript is for people with wrinkly brains
( thats a compliment lol )
did you mean that
Yes, I'm smooth brain so everything I do is vanilla
everything