error_handler 1.0.4 copy "error_handler: ^1.0.4" to clipboard
error_handler: ^1.0.4 copied to clipboard

outdated

error handler for all http client in dart like dio, chopper http and more

example/error_handler_example.dart

import 'package:dio/dio.dart';
import 'package:error_handler/error_handler.dart';
import 'post.dart';

/// first create [Dio] api call
FutureResponse<Post> getPost() async {
  const path = "https://jsonplaceholder.typicode.com/posts/1";

  final response = await Dio().get(path);
  return response.convert(Post.fromJson);
}

/// wrap the api call with [ErrorHandler.future]
Future<void> main() async {
  final state = await errorHandler.future(getPost);

  state.whenOrNull(
    data: (post, response) {
      print("title: ${post.title}");
    },
    error: (error) {
      print(getErrorMessage(error));
    },
  );
}
17
likes
0
pub points
52%
popularity

Publisher

verified publishermatheer.com

error handler for all http client in dart like dio, chopper http and more

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

chopper, dio, freezed_annotation

More

Packages that depend on error_handler