PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 13, 2022

[FIXED] How can i make the interceptor run a function on error exept for one specific request?

 October 13, 2022     axios, react-query     No comments   

Issue

this is my interceptor:

axios.interceptors.response.use(
(response) => {
     if (error.response?.status === 403) {
        unstable_batchedUpdates(() => {
            // to force react state changes outside of React components
            useSnackBarStore.getState().show({
                message: `${i18n.t('forbidden')}: ${error.toJSON().config.url}`,
                severity: 'error',
            })
        })
    }
    return Promise.reject(error)
}
)

I want this behavior all the time except when I make this specific call or at least except every head call

export const companiesQueries = {
    headCompany: {
        name: 'headCompany',
        fn: async (companyId) => {
            return await axios.head(`/companies/${companyId}`)
        },
    },

Solution

fixed by applying these changes to the api call:

const uninterceptedAxiosInstance = axios.create()

headCompany: {
    name: 'headCompany',
    fn: async (companyId) => {
        return await 
        uninterceptedAxiosInstance.head(`/companies/${companyId}`)
        },
    }


Answered By - Foris
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing