title: Error: Request failed with status code 400 - AXIOS NODEJS
body: <p>I have a problem connecting to the api by axios <code>Error: Request failed with status code 400</code></p>
  
  <p>Can someone help me please?</p>
  
  <p>My services/api.js: `</p>
  
  <pre><code>const axios = require("axios");
  
  const api = axios.create({
    baseURL: "https://url.com"
  });
  
  api.interceptors.request.use(async config =&gt; {
      config.headers.access_token = `token123`;  
      return config;
  });
  
  module.exports = api;
  </code></pre>
  
  <p>My controller: </p>
  
  <pre><code> const api = require('services/api');
      router.post('/', async (req, res) =&gt; {    
         try {
           const response = await api.post("/api", JSON.stringify(data));
           return response;
          } catch (err) {          
            return res.status(400).send({ erro: err })
          }
      })
  
      module.exports = app =&gt; app.use('/routes', router)
  </code></pre>
  
  <p>But while I make the request, I get the error </p>
  
  <pre><code>{
    "erro": {
      "message": "Request failed with status code 400",
      "name": "Error",
      "stack": "Error: Request failed with status code 400\n    at createError (/Library/WebServer/Documents/api/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/Library/WebServer/Documents/api/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/Library/WebServer/Documents/api-nex/node_modules/axios/lib/adapters/http.js:236:11)\n    at IncomingMessage.emit (events.js:228:7)\n    at endReadableNT (_stream_readable.js:1185:12)\n    at processTicksAndRejections (internal/process/task_queues.js:81:21)",
      "config": {
        "url": "/api",
        "method": "post",
        "data": "{"\myjson\": "\json\"}",
        "headers": {
          "Accept": "application/json, text/plain, */*",
          "Content-Type": "application/x-www-form-urlencoded",
          "access_token": "token123",
          "User-Agent": "axios/0.19.2",
          "Content-Length": 398
        },
        "baseURL": "https://url.com",
        "transformRequest": [
          null
        ],
        "transformResponse": [
          null
        ],
        "timeout": 0,
        "xsrfCookieName": "XSRF-TOKEN",
        "xsrfHeaderName": "X-XSRF-TOKEN",
        "maxContentLength": -1
      }
    }
  }
  </code></pre>