My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

How to get "403 Forbidden" code response message through axios ?

Mrudang Shah's photo
Mrudang Shah
·May 8, 2019

I am working with a Token API with using of this JWT plugin :

It is working well with 200 status code. But how can i handle 403 Forbidden error message ? As currently i am not able to display an error message.

export const LoginAction = (FormData) => {
  return (dispatch) => {
    axios({
      method: 'post',
      headers: { 'Content-Type': 'application/json' } ,
      url: API,
      data: FormData,
      })
      .then(function (response) {
        localStorage.setItem('tpwToken', response.data.token);
        dispatch({
          type: 'SET_USER',
          user: response.data,
          message: response.data.message
      })
    })
    .catch(function(error){
      console.log(error.message)
    })
  }
}

Screenshot from 2019-05-08 10-50-30.png