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

179
Visualizações
How to check that ApolloError is caused by client internet connection?

ApolloError has networkError prop, but it is set when server responds with 4** or 5** status code.

And how to check that the problem is caused by bad internet connection?

try {
   apolloClient.query(someQuery)
} catch (error) {
  if (isInternetConnectionError(error)) { // how to check this?
    Alert.alert('Please check your internet connection!')
  } else {
    logException(error);
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Seems that there is not good way to get that (nice work Apollo), but this is the exact error state that comes when there is no internet:

export const isNetworkError = (error: unknown) => {
  return (
    error instanceof ApolloError &&
    error.message === 'Network request failed' &&
    error.graphQLErrors.length === 0 &&
    error.clientErrors.length === 0 &&
    error.networkError &&
    Object.keys(error.networkError).length === 0
  );
};

Actual for "@apollo/client": "3.4.7"

Or here is much shorter version that should work:

export const isNetworkError = (error: unknown) => {
  return (
    error instanceof ApolloError &&
    error.message === 'Network request failed'
  );
};
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