You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Note that the error was actually on line 195 in stock, the Jason.decode! line — it's just that I had added a File.write("/tmp/response", body) line to see what was happening.)
It's certainly entirely reasonable for Nostrum to refuse to start up while Discord is down, but the error message could be a lot better — this makes it look like there's some protocol-level error, when the error is just that I'm getting an HTML page (a stock 502 Bad Gateway page) instead of a JSON page.
I'd submit a PR, but I'm not sure how best to fix this. There's at least a couple options here:
Check the content-type of the reply, to ensure it's application/json
Just try Jason.decode (rather than decode!) and handle the {:error, err} case specially.
The text was updated successfully, but these errors were encountered:
Thanks for the report! I'm partial to the second option - moving away from Jason.decode!/2 and using the non-banged version. I'm not sure what the flow for this would look like though. If we encounter this error, what do we do about it?
Yeah, I'm not sure. It's probably entirely reasonable to still just raise an exception and die, just with a more helpful message (like Got a "502 Bad Gateway" response with a non-JSON payload) to make it clear what's happening.
Having the Ratelimiter die will also mean that anyone who is currently issuing an API call will also raise an exception (and probably die, and hopefully be resurrected by their supervisor tree). That also seems good to me — I imagine you don't really want an API outage to be reported as an {:error, %Nostrum.Error.ApiError{...}} tuple, because that's for actual API errors, with defined behaviour. We're very much in the realm of undefined behaviour here, which is what exceptions are for, I think.
So Discord went down for a bit, and I started getting this error while trying to start my bot:
(Note that the error was actually on line 195 in stock, the
Jason.decode!
line — it's just that I had added aFile.write("/tmp/response", body)
line to see what was happening.)It's certainly entirely reasonable for Nostrum to refuse to start up while Discord is down, but the error message could be a lot better — this makes it look like there's some protocol-level error, when the error is just that I'm getting an HTML page (a stock
502 Bad Gateway
page) instead of a JSON page.I'd submit a PR, but I'm not sure how best to fix this. There's at least a couple options here:
content-type
of the reply, to ensure it'sapplication/json
Jason.decode
(rather thandecode!
) and handle the{:error, err}
case specially.The text was updated successfully, but these errors were encountered: