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

235
Views
How to stop a request in Axios?

I would like to stop a request when the database is offline or when there is a problem with the backend conexion, but I don't know how to do this.

My Axios settings are as follows:

import axios from "axios";
import AsyncStorage from '@react-native-async-storage/async-storage';

const baseURL = 'http://192.168.1.43:4000/server';

const gestorMedicoApi = axios.create({ baseURL});

gestorMedicoApi.interceptors.request.use(
    async (config) => {
        const token = await AsyncStorage.getItem('token');
        if (token) {
            config.headers!['x-token'] = token;
        }

        return config;
    }
)
export default gestorMedicoApi;

And an request example is the following:

    const signUp = async ({ nombreEmpresa, email, telefono, contraseña }: RegisterData)  => {
        try {
            const resp = await gestorMedicoApi.post<Response>('/user/createUser', { nombreEmpresa, email, telefono, contraseña }); 

            dispatch({
                type: 'signUp',
                payload: {response: resp.data}
            })

        } catch (error: any) {
            dispatch({ type: 'addError', payload: {response: {status: "NOK", message: "Se ha producido un error al conectar con la base de datos."}} })
        }
    };

If the next line fails:

 const resp = await gestorMedicoApi.post<Response>('/user/createUser', { nombreEmpresa, email, telefono, contraseña });

The flow go into the catch, but the request tries to conect again and again, so I would like to stop the request if it fails.

How can I get it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

axios doesn't make repetitive requests. It is possible that your component is being re-rendered or is stuck in a loop which is calling your sign-up function continously. Please re-check your code and if possible provide more snippets.

about 4 years ago · Juan Pablo Isaza 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!