Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't consume api responses returning single strings #93

Closed
aalejandromr opened this issue Sep 3, 2021 · 0 comments · Fixed by #96
Closed

Can't consume api responses returning single strings #93

aalejandromr opened this issue Sep 3, 2021 · 0 comments · Fixed by #96
Assignees

Comments

@aalejandromr
Copy link
Contributor

Getting JSON.parse: unexpected character at line 1 column 1 of the JSON data because the response from the API is a single String (Token).

Using the following config

const externalApi = configureApi({
      root: process.env.ELAVON_TRANSACTION_TOKEN_ENDPOINT,
      mode: 'cors'
    })
  
    externalApi.post('/hosted-payments/transaction_token', { 
      ssl_merchant_id: process.env.ELAVON_SSL_MERCHANT_ID, 
      ssl_user_id: process.env.ELAVON_SSL_USER_ID, 
      ssl_pin: process.env.ELAVON_SSL_PIN, 
      ssl_transaction_type: "ecspurchase"
    })
    .then((data) => {
      console.log(data); // Doesn't reach this point
    })
    .catch((results) => {
      console.log("HERE"); // Throws the exception and consoles this one
    });
    

Response from the api

image

Content-Type is application/json

While using axios, I'm able to get the response back as a String but lp-requests fails with the above error. It looks like axios by default will return the plain response if JSON.parse fails.

@chawes13 chawes13 self-assigned this Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants