Friendly Errors
The route fails in a different way each time you click #ask: a 429 (with Retry-After: 5), a 500, a 401 whose body contains a made-up key, a 502 whose body is an HTML page, and finally a success. Right now the page prints whatever text the server sent.
Fix the click handler. On failure, leave #answer empty and show only these messages in #error. 429: Mitra is busy. Try again in 5 seconds. (take the 5 from the Retry-After header). 401: Mitra is not set up correctly. The shop has been told. 500 and 502: Mitra had a problem on its side. Please try again. On success, show answer from the JSON in #answer and clear #error. The HTML page from the 502 must not crash your code.
What Check tests
- A 429 with
Retry-After: 5showsMitra is busy. Try again in 5 seconds.and no answer - A 500 shows
Mitra had a problem on its side. Please try again. - A 401 shows
Mitra is not set up correctly. The shop has been told.and never the key - A 502 with an HTML page shows the same message as a 500, without errors
- A success shows the answer and clears
#error
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Your page
Console
Nothing logged yet.