title: axios request cannot read property of undefined
body: <p>I am trying to make a backend request to a server and I continue to get a <code>response.data</code> back that is some HTML as a string that says <code>TypeError: Cannot read property of undefined</code></p>
  <p>I need to pass it a <code>data</code> object that looks like so:</p>
  <pre><code>const data = {
    visitorId,
    patientId: oldPatientId,
    doctorId
  }
  </code></pre>
  <p>and I need to pass it a json web token like so:</p>
  <pre><code>const userJWT = jwt.sign(
    {
      _id: visitorId,
      refreshCount: 0
    },
    this.localConfig.spyrt.jwtSecret
  )
  </code></pre>
  <p>and headers that look like so:</p>
  <pre><code>const headers = {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${userJWT}`
  }
  </code></pre>
  <p>I am doing this inside an asynchronous method like so:</p>
  <pre><code>async jwtTest(visitorId: number, oldPatientId: number, doctorId: number): Promise&lt;void&gt; {
    const data = {
        visitorId,
        patientId: oldPatientId,
        doctorId
      }
  
      const userJWT = jwt.sign(
        {
          _id: visitorId,
          refreshCount: 0
        },
        this.localConfig.spyrt.jwtSecret
      )
      
      const headers = {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${userJWT}`
      }
  
      if (this.localConfig.spyrt.active) {
        const dto = await axios.post(visitURL, data, {headers}).then((response) =&gt; {
          console.log(response.data);
        }).catch((error) =&gt; {
          console.log(error);
        });
      }
  }
  
        
  </code></pre>
  <p>I am concerned that my axios code is not set up correctly. I am getting cannot read property undefined and a 500 <code>statusCode</code> error.</p>
  <p>I have consulted with the axios documentation to the best of my ability. Does anyone see anything wrong with my setup?</p>
  <p>I tried this implementation:</p>
  <pre><code>if (this.localConfig.spyrt.active) {
    await axios.post(visitURL, data, {headers}).then(function(response) {
    console.log(JSON.stringify(response.data));
  }).catch(function(error) {
    console.log(error);
  })
  }
  </code></pre>
  <p>and with this one I get the exact same response.</p>
  <p>The closest I have to understanding that API is the previous engineer's code whose setup looked like this:</p>
  <pre><code>try {
    let response = await fetch(visitURL, {
      method: 'POST',
      headers: {
       'Content-Type': 'application/json',
       'Authorization': 'Bearer ' + acct.jwt
       },
       body: JSON.stringify(visit)
      });
      if (response.ok) {
       let result = await response.json();
       callback(result);
      } else {
        throw new Error('Model: createVisit failed!');
      }
    } catch (error) {
      console.log(error);
    }
  </code></pre>