Can we pass errors as props from catch block in reactJS and show them in new reusable component where props will resemble different errors

Viewed 60

Below method isn't working. I also tried using useHistory but how to pass props using useHistory , Redirect method also not working

For example

Inside Functional Component{



 instance.get(url).catch((error)=>{

 
        if(error.response){

          if(error.response.status===404){
                  
                   <ErrorComponent err={error.response.status}/>
                   console.log("Page Not Found");
               }
          if(error.response.status===400){
                
               <ErrorComponent err={error.response.status}/>
               console.log("Bad Request")
           }
      }
  }
}
0 Answers
Related