intuit / oauth-jsclient

Intuit's NodeJS OAuth client provides a set of methods to make it easier to work with OAuth2.0 and Open ID
https://developer.intuit.com/
Apache License 2.0
120 stars 154 forks source link

`.getJSON` method invoked on xml throws sdk error, masking the original problem #118

Open railz-guli opened 3 years ago

railz-guli commented 3 years ago

We're using nodeJs sdk, version 3.0.2 and for certain requests we make with makeApiCall the error we're getting is Error: AuthResponse is not JSON at AuthResponse.getJson (/var/app/current/node_modules/intuit-oauth/src/response/AuthResponse.js:106:29) at OAuthClient.createError

After investigating the error it came to our attention that the sdk is getting back an xml instead of JSON. Moreover, the way sdk handles/throws/logs the error masks the original error we're getting in the xml (we want to see the issues in production). For the short term, if you could add logs before calling .getJSON on the response it would be very helpful.

Thank you!

aiden5221 commented 3 years ago

I'm having this same issue, whenever I attempt to make a request with makeApiCall I'm receiving the error Error: AuthResponse is not JSON at AuthResponse.getJson (~\node_modules\intuit-oauth\src\response\AuthResponse.js:106:29)

I'm receiving this error after using the code example from app.js. I believe my authorization flow is correct so I don't know where to go from here.

akoskm commented 3 years ago

I can also confirm this. We tried setting the headers in makeApiCall but it had no effect:

      await oAuthClient.makeApiCall({
        url,
        method: "GET",
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json",
        },
      })

the response is still coming back as XML:

<?xml version="1.0" encoding="UTF-8"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2021-07-19T22:39:33.743-07:00">
   <Fault type="AuthenticationFault">
      <Error code="100">
         <Message>General Authentication Error</Message>
         <Detail>AuthenticationErrorGeneral: SRV-110-Authentication Failure , statusCode: 401</Detail>
      </Error>
   </Fault>
</IntuitResponse>
syJSdev commented 2 years ago

Hi @abisalehalliprasan , This issue requires an urgent fix. I can't get what is the API response. Even if I set the Accept header to 'application/json', the API returns in xml format. also, this issue only occurs when the API responds with an error.