TootSDK icon indicating copy to clipboard operation
TootSDK copied to clipboard

User friendly error messages

Open Tunous opened this issue 8 months ago • 1 comments

The way TootSDK currently works is that when it encounters errors during API calls it wraps them inside of TootSDKError and throws. This based on my experience most commonly results in invalidStatusCode case being thrown. I implement error handling by either handling this case and searching for http status codes I know how to handle or fallback to showing generic error with localized description displayed to user. Unfortunately I noticed that is not the best approach as it usually results in “Invalid HTTP status code” message being displayed.

For example, recently I attempted to upload post with both video and images as attachments. Apparently this case is not supported and Mastodon responded with http 422. This resulted in my app showing mentioned invalid status code message. But in the logs from response I saw below error:

{
  "error": "Nie możesz załączyć pliku wideo do wpisu, który zawiera już zdjęcia"
}

Translating from polish it exactly describes what happened: that you can’t upload videos together with images. Now that is a message I would like to see displayed in the app.

I’m opening this issue to suggest improving error handling in the SDK to make it possible to display errors from API like this one to the user.

Tunous avatar Oct 08 '23 15:10 Tunous