title: how can I pass success or error message using react-toastify when using axios method
body: <p><strong>I want to show success or error message depending upon the HTTP response status code that I will receiving upon sending my axios request ,using react-toastify (For example if the status code is 406 react-toastify should show a error message like &quot;Some fields are empty&quot; or if status code is &quot;422&quot; is should show a error message like &quot;email already registered&quot; and in case of status code &quot;200&quot; react-toastify should show a message &quot;Account created successfully&quot;) on frontend.</strong></p>
  <p><strong>Here is my backend api code</strong></p>
  <pre><code>router.route('/register').post(upload.single('photo'), (req, res) =&gt; {
  
    const name = req.body.name;
    const email = req.body.email;
    const phone = req.body.phone;
    const work = req.body.work;
    const password = req.body.password;
    const cpassword = req.body.cpassword;
    const photo =  req.file.filename;
  
    
    if(!name || !email || !phone || !work || !password || !cpassword || !photo ){
      return res.status(406).json({message:&quot;Some fields are missing&quot;}) ;
      
  }
    User.findOne({email: email})
    .then((userExist)=&gt;{
           if (userExist){
               return res.status(422).json({Error:&quot;Email already registered&quot;});
              
         }
  
         const newUserData = {
          name,
          email,
          phone,
          work,
          password,
          cpassword,
          photo
      }
  
      const newUser = new User(newUserData);
         newUser.save().then(()=&gt;{
          res.status(201).json({message:&quot;user created successfuly&quot;});
          alert(&quot;user created succcessfully&quot;)
               }).catch((err)=&gt;res.status(500).json({error:&quot;registeration failed&quot;})
               );
           }).catch((err)=&gt;{console.log(err);});
           
           });
  
  </code></pre>
  <p><strong>Here is the function on front that fetch data from input field</strong></p>
  <pre><code>   const handleSubmit = (e) =&gt; {
          e.preventDefault();
          let url = 'http://localhost:3000/register'
          const formData = new FormData();
          formData.append('name', newUser.name);
          formData.append('email', newUser.email);
          formData.append('phone', newUser.phone);
          formData.append('work', newUser.work);
          formData.append('password', newUser.password);
          formData.append('cpassword', newUser.cpassword);
          formData.append('photo', newUser.photo);
  
          axios.post(url , formData)
               .then(res =&gt; {
                  console.log(res)
                  history.push('/login')
                  
               } )
               .catch(err =&gt; {
                  console.log(err);
                  
               });
      }
  </code></pre>