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 Answer 1

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)
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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