Throwing an exception depending on value type might not be optimal. Checking response.statusCode could be a more reliable approach
Another more reliable approach is to agree with your back-end developer to include a new object with every request. This object indicates whether this response is a successful or failed response. This way you can create a global utility function that knows how to handle all errors.
https://github.com/ikema77/flutter_auth/blob/0b86b7d22c968fdd363c173abcfbd6dd2510f919/lib/providers/auth.dart#L40-L41
Throwing an exception depending on value type might not be optimal. Checking
response.statusCode
could be a more reliable approachAnother more reliable approach is to agree with your back-end developer to include a new object with every request. This object indicates whether this response is a successful or failed response. This way you can create a global utility function that knows how to handle all errors.