Error handling for station not always working
Closed this issue · 9 comments
The error normalizing misses some TFL station stuff.
if (typeof err === "object" && (err as any).error && typeof (err as any).error === "string") {
throw new Error((err as any).error);
}
if (typeof err === "object" && (err as any).error && typeof (err as any).error === "object") {
throw new Error((err as any).error.message || JSON.stringify(err));
}
It might be that (err as any).error
is not a string and such the current function just returens [object]
so adding the above checks solves that
@StrathCole do you happen to know a reproducible way to make Station throw such an error?
@AaronCQL I think if you send too few gas fees for example. It should always be such an error.
@AaronCQL here is an example that is returned from TFL Station:
Error: {"chainID":"columbus-5","error":{"code":3},"fee":"{\"amount\":[{\"denom\":\"uluna\",\"amount\":\"15482700\"},{\"denom\":\"uusd\",\"amount\":\"1085297.03\"}],\"gas_limit\":\"546609\"}","id":1711355526898,"memo":"","msgs":["{\"@type\":\"/cosmwasm.wasm.v1.MsgExecuteContract\",\"contract\":\"terra1l7vy20x940je7lskm6x9s839vjsmekz9k9mv7g\",\"msg\":{\"swap\":{\"belief_price\":\"0.005638608421035003\",\"deadline\":1711356125159,\"max_spread\":\"0.00500\",\"offer_asset\":{\"amount\":\"217059406\",\"info\":{\"native_token\":{\"denom\":\"uusd\"}}}}},\"sender\":\"xxxxxxxxxxxxxxxxxxxxxxxxxx\",\"funds\":[{\"denom\":\"uusd\",\"amount\":\"217059406\"}]}"],"origin":"xxxxxxxxxxxxxxxx","purgeQueue":true,"result":{},"success":false,"uuid":"xxxxxxxxxxxxxxxxxxxxxxx"}
Sadly the "error code 3" is very generic and covers many different things.
As you can see, "error" property of the object is an object itself, so your current handling cannot deal with it.
I think station mobile also returns that kind of object.
Sadly the "error code 3" is very generic and covers many different things. As you can see, "error" property of the object is an object itself, so your current handling cannot deal with it. I think station mobile also returns that kind of object.
If the error thrown is an object itself, it should already be handled for by this line, where the object is stringified:
I think for station prior to changing it to keplr handling you had something like
if (typeof err === "object" && (err as any).error) {
throw new Error((err as any).error);
}
Which led to err.error being interpreted as string, so [object Object]
But with the handling you have now in KeplrExtension, while the error is probably (could not test due to #48) displaying as "Unknown error: {xxxxxxx}" now, it's very hard to process such errors in the dApp correctly. You would need to strip the "Unknown error: " part and then check what the remainder is. It would be good if that could be improved somehow.
Maybe a custom Error object from the cosmes library that has fields like "message", "code" and "raw" (with the latter holding the original error) so the dApp can decide how to handle the error.
Maybe a custom Error object from the cosmes library that has fields like "message", "code" and "raw" (with the latter holding the original error) so the dApp can decide how to handle the error.
Indeed this would be the best approach. Would you like to contribute to this?
Indeed this would be the best approach. Would you like to contribute to this?
I will check on it 👍