title: How do I send error message from server to client?
body: <p>I'm making some requests from my express server, and I'm wondering how I can pass an error message to the client side.  I want to be able to see the error message when I console log from the client as well as from the server, but I'm not sure how to relay this message back to the client to make that possible.</p>
  
  <p>Here is an example of a request from my server.js file</p>
  
  <pre class="lang-js prettyprint-override"><code>app.get('/assign*', (request, response) =&gt; {
      var baseurl = 'https://OURACC.nocrm.io/api/v2/'
      var apikey = crmkey;
  
      var pathname = request.url; // retrieves the requested pathname (ie, /crm/path)
      pathname = pathname.split('?');
      pathname = pathname[0].split('/')
      var parameters = request.query.params;
      var path = pathname[2]; // gets request path for the crm
  
     var lead_id = parameters.lead_id
      var user_id = parameters.user_id
  
      var params = {
          user_id: user_id
      }
  
      if(path === 'leads'){
  
              axios.post(baseurl + path + '/' + lead_id + '/assign',
                  params
              ,{
                  headers: {'X-API-KEY': apikey, content_type: "json", accept: "application/json"} 
              }).then(function(res){
                  response.send(res.data);
              }).catch(function(error){
                  console.log("ERROR in /assign/leads/{id}/assign" + error);
              })
  
      }
  
  })
  </code></pre>
  
  <p>This is what the call to this request looks like client side</p>
  
  <pre class="lang-js prettyprint-override"><code> $.get('/assign/leads', {params: data}).then(response =&gt; {
                  console.log(response);
              }).catch(error =&gt; {
                  console.log(error);
              })
  </code></pre>
  
  <p>I've tried this server side</p>
  
  <pre class="lang-js prettyprint-override"><code>response.send(error)
  </code></pre>
  
  <p>but this doesn't return me anything client side like I was expecting.</p>
  
  <p>I'm sure this is something simple, but I couldn't find much online about it, thanks.</p>