javascriptnode.jspostaxiosresponse

Axios response Error: certificate has expired


I'm using axios to send request to diro to create an user with endpoint /user/create.

However, I keep getting an error like this:

Error response: { Error: certificate has expired
    at TLSSocket.onConnectSecure (_tls_wrap.js:1055:34)
    at TLSSocket.emit (events.js:198:13)
    at TLSSocket.EventEmitter.emit (domain.js:448:20)
    at TLSSocket._finishInit (_tls_wrap.js:633:8)

Here is my request:

const DIRO_API_KEY = ******
createUserToDiro = ({
  phone,
  first_name,
  last_name,
  birth_date,
  mcc_code
}) => {
  const mobile = phone;
  const firstname = first_name;
  const lastname = last_name;
  const dob = formatDiroDob(birth_date);
  const mcc = mcc_code;
  axios.post('https://api.dirolabs.com/user/create'), {
    firstname,
    lastname,
    dob,
    mobile,
    mcc,
    apikey: DIRO_API_KEY
  })
  .then(rs => console.log('Success response:', rs))
  .catch(err => console.log('Error response:',err));

};

What is causing this issue and is there any way to fix it ?


Solution

  • Axios library error clearly mentioned that the certificate has expired.

    Please ask diro to renew SSL certificate.

    Another way we can skip checking for SSL in Axios npm library as follows

    const axios = require('axios');
    const https = require('https');
    
    // At request level
    const agent = new https.Agent({
        rejectUnauthorized: false
    });
    
    // Make a request for a user
    axios.get('/user/create', { httpsAgent: agent })
      .then(function (response) {
        // handle success
        console.log(response);
      })
      .catch(function (error) {
        // handle error
        console.log(error);
      })
      .finally(function () {
        // always executed
      });
    

    This works.