Monday 1 May 2017

axios not triggering "then"

I have built a function that makes an API call using axios. The issue I am running into is that even when I get a status = 200, I am not able to trigger the "then" method, only the "catch" method.

Here is the function in question which I am requiring into a different file where it is used:

import_csv: function( url, clist, ticket, apptoken, cdata ) {
      var data = "<qdbapi>";
      data += "<usertoken>" + ticket + "</usertoken>";
      data += "<apptoken>" + apptoken + "</apptoken>";
      data += "<records_csv><![CDATA[" + cdata + "]]></records_csv>";
      data += "<clist>" + clist + "</clist>";
      data += "</qdbapi>";


      return axios({
         method: 'post',
         url: url,
         data: data,
         headers: {
            'Content-Type': 'application/xml',
            'QUICKBASE-ACTION': 'API_ImportFromCSV',
            'X_QUICKBASE_RETURN_HTTP_ERROR' : 'true'
         }
      });

   }

Here is where it is used in a separate JS file where only the "catch" is firing - even though I am getting a 200 response:

qb.import_csv( url, clist, ticket, apptoken, cdata )
        .then(function(res){
            console.log(res);
        }).catch(function(er) {
            console.log(er);
        });

But here is the beginning of the response I am getting back (200 success). Why is the "catch" method getting fired and not the "then" method?

{
    status: 200,
    statusText: 'OK',
    headers: {
        'content-length': '482',
        'content-type': 'application/xml',



via Jim M

No comments:

Post a Comment