Vârli
I have this code to make a get request to an API
TypeScript
function fetchUserListPerPage(page) {
return new Promise(async (resolve, reject) => {
try {
const response = await axios
.get(`${process.env.CHARA_API_URL}/api/v1/bestvalue/b2b/customer/list?_ipp=100&_p=${page}`, {
headers: {
Authorization: `${process.env.CHARA_API_KEY}`
}
});
resolve(response.data);
} catch(error) {
console.log(error);
reject({ Content: { Records: [] } });
}
});
}
And sometimes the request fails with the getaddrinfo EAI_AGAIN error
TL;DR
Code is making a GET request using axios to an API, sometimes resulting in a getaddrinfo EAI_AGAIN error. This error typically occurs due to DNS lookup failure. Adding a timeout option in axios to handle this error might help:
```javascript
function fetchUserListPerPage(page) {
return new Promise(async (resolve, reject) => {
try {
const response = await axios
.get(`${process.env.CHARA_API_URL}/api/v1/bestvalue/b2b/customer/list?_ipp=100&_p=${page}`, {
headers: {
Authorization: `${process.env.CHARA_API_KEY Recommended threads
- Issue with Authentication
I am stuck with authentication using appwrite. I am getting bad request 400 error when trying to register though we already have project, database, collection c...
- Appwrite CLI not working as expected
Until yesterday I was authenticated in my Appwrite instance through the CLI, and I was able to get my functions and deploy them manually. Today, when I went ba...
- oAuth Problem with session (Google)
I'm currently working on a project using Next.js and have set up Google OAuth authentication. The consent screen flow is functioning correctly, and it redirects...