Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
React async fetch with 503 Service Unavailable

I am trying to fetch 20 random users data from 'https://randomuser.me/api' and in some cases, I get the 503 Service Unavailable error.

I tried to resolve the problem with this kind of code.

async function fetchDriver() {
    const driver = await fetch(driverUrl)
        .then((response) => {
            if (response.status === 200) {
                return response.json();
            }
            if (response.status === 503) {
                return fetchDriver();
            }
        })
        .then((data) => console.log(data))
        .catch((error) => {
            console.log(error);
            fetchDriver();
        });
    return driver;
}

do {
    const geoPosition = fetchGeoPosition();
    const phoneNumber = fetchPhoneNumber();
    const licenseNumber = fetchLicense(3);
    const speed = fetchSpeed(60, 200);
    const driver = fetchDriver();
    const first = driver.name.first;
    const last = driver.name.last;
    fetchedCars.push({
        licenseNumber,
        first,
        last,
        phoneNumber,
        geoPosition,
        speed,
        favorite: false,
        more: false,
    });
} while (fetchedCars.length < 20);

But console.log(data) in some cases still shows the value of undefined and I just don't know what to do with this.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

random user API has a rate limiter. use this to fetch multiple users in one request (for example 20 users):

https://randomuser.me/api/?results=20

check the documentation here

This GitHub thread mentions the rate-limiting and the solution I've included

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda