Improve error handling in case the server does not return json
Sentry Issue: APP-58
TypeError: type 'Null' is not a subtype of type 'Map<String, dynamic>'
File "user_data_source.dart", line 43, in UserDataSource.getCurrentUser.<fn>
File "user_repository_impl.dart", line 26, in UserRepositoryImpl.getCurrentUser
File "settings.dart", line 69, in SettingsPageState.init.<fn>
When the server does not return json (for example on proxy error), this error occurs. We should handle this and show a message to the user.
@leschbenedikt this happened multiple times in different repo implementations. Is that something that will be fixed by the reimplementation of the repos? Or something extra to look out for?
Wanted to look into it but haven't had time.
I will check that tomorrow morning and report back
Unfortunately this will not be fixed. This kind of error is occurring when the response is not returning a JSON (Map<String, dynamic>) For example when the token expires and the request returns a 401.
The reason is that most of APIService that a now called data_sources expect only a successful response and do not handle errors. The logic of these didn't change. We just added a layer.
In the future we will need to react to those errors and hand them back to the UI where we need to decide what to do (is it recoverable or not etc.)
Thanks for the explanation.
What's interesting here is that the API will always return json, even in case of errors. Still, it could be the case that the server responds with non-json, for example when a proxy is returning something else.
I'll rephrase this issue to improve error handling.
Your're right it returns json in the 401 case. I'm not completely sure in what case it returns an empty response. But in the case where it's still json it's the wrong json because the data source expects the actual data json and it's just an error object