0

I use Javascript SDK to connect to Horizon. It works, but I also would like the specific error if it doesn't work. See my code below.

How can I access the specific code returned from horizon (e.g. 404)? Right now I only get "Error".

Thanks in advance.


// --- check if account is active
server.accounts()
    .accountId(publicKey)
    .call()
    .then(function (accountResult) 
      ...
    })
    .catch(function (err) {
        alert(err);
        document.getElementById("error").innerHTML = 'Account not valid or inactive1!';
    })
1

The error object contains response field with HTTP response details from the server. You can refer to response.status to retrieve the status code.

if (err.response && err.response.status === 404) {
  console.error('Account does not exist.')
}
else {
  console.error(err)
}
  • 1
    Thanks, just what I was missing. I sent you some lumen on your expert donation address. – bluesky Mar 2 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.