Crash when server is offline and returning non-pixelfed error page
When the server is offline and behind cloudflare for example, the app will get back an error but won't be able to interpret it as an Error
. This crashes with a JsonSyntaxException
:
Stacktrace: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
......
at com.google.gson.Gson.fromJson(Gson.java:813)
at org.pixeldroid.app.posts.feeds.CommonFeedFragmentUtilsKt$initAdapter$3.invoke(CommonFeedFragmentUtils.kt:86)
See code here: fromJson throws JsonSyntaxException
To fix:
- Try/catch the error (catch Exception superclass in case anything else goes wrong)
- If exception caught: try HTTP error code, else print generic error?
Edited by Matthieu