http exception flutter
// models/http_exception.dart
class HttpException implements Exception {
final String message;
HttpException(this.message);
@override
String toString() {
return message;
}
}
// in some other file
if (json.decode(response.body)['error'] != null) {
throw HttpException(json.decode(response.body)['error']['message']);
}
// in ui file
try{
} on HttpException catch(error) {
} catch (error) {
}