Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
¿Hay alguna forma de manejar la reacción useQuery con el código de estado 401 sin 10 segundos de tiempo de carga?

Cuando la página de reacción se cargue inicialmente, realizará una consulta automática. La intención de me-query es obtener al usuario actual si tiene una sesión activa.

En el middleware de autenticación se ejecutará este código:

 function authenticate(req: Request, res: Response, next: NextFunction) { if (!req.session || !req.session.userId) { return res .status(401) .json({ error: "Missing login, must login/register" }); } next(); }

Y en el cliente realizará esto

 export const fetchUser = async (): Promise<User> => { const res = await axios.get(`/profile`); if (res.data) return res.data; if (res.status === 401) throw new Error("Could not get profile"); throw new Error("Could not get profile"); }; const { data, error, isLoading, isFetching, status } = useQuery<User, Error>( "user", fetchUser );

Lo que sucede actualmente es que vuelve a ejecutar la misma consulta varias veces. Pero si cambio return res.status(401).json({ error: "Missing login, must login/register" }); para return res.status(200).json({ error: "Missing login, must login/register" }); , luego regresa de inmediato y no tendré que mirar mi página actualizándose durante 10 segundos.

¿Es posible hacer que useQuery solo realice una solicitud al servidor? ¿Preferiblemente obtener la respuesta rápida que obtengo con el estado de 200?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Encontré una solución. Es posible establecer la cantidad de reintentos que se pueden hacer. Puse el mío en 0, evitando así la larga espera.

 const { data, error, isLoading, isFetching, status, failureCount } = useQuery< User, Error >("user", fetchUser, { retry: 0, });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!