3box / 3box-js

3Box JavaScript SDK: User identities, storage, messaging
MIT License
207 stars 65 forks source link

How can I capture await.getProfile errors? #926

Closed sanmiawi closed 3 years ago

sanmiawi commented 3 years ago

When I try to use the getProfile method it works with a valid address but I would like to read the error returned if an invalid address is entered example await threeBox.getProfile('abcdefghijklmnopqrstuvwxyz')

returns the following error in developer tools {"status":"error","message":"Address link not found, address does not have a 3Box or is malformed"}

but I cannot read this error using try/catch or threeBox.getProfile('abcdefghijklmnopqrstuvwxyz').catch(err => {console.error(err)}); sequence

how can I read the error in my code?

oed commented 3 years ago

Hey unfortunately it's not possible to catch these as Chrome and other browsers always will log whenever 404s happen, regardless of if you catch the error or not :/

sanmiawi commented 3 years ago

Hi, I do not mind that the error is logged in console. I would like to know that it occurred and make a different decision based on the occurrence of an error. If there is no thrown error, do you think its possible to parse the response from connect.3box.io?

sanmiawi commented 3 years ago

Hi, its ok. I think I will just use axios get request https://ipfs.3box.io/profile?address= and parse the result from that before using the getProfile function. Thanks