vendredi 29 mai 2020

Axios - Interceptors: prevent further handling by original caller

I have a succesful response interceptor for my Axios instance. Under certain circumstances I basicly want to prevent further execution of .then()'s and .catch()'s.

axiosExtended.interceptors.response.use(response => successHandler(response), error => errorHandler(error))

function successHandler(response) {
    const relativeRequestUrl = response.config.url;
    const relativeResponseUrl = trim(response.request.responseURL.replace(response.config.baseURL, ''), '/');

    if (relativeRequestUrl !== relativeResponseUrl) {
        // dont return anything to original caller. No then. No catch.
        router.push(relativeResponseUrl)
    }

    // get handled by original caller...
}

Aucun commentaire:

Enregistrer un commentaire