Answers for "http exception flutter"

0

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) {
  
}
Posted by: Guest on July-12-2021

Browse Popular Code Answers by Language