handleExceptions method

Future<Response> handleExceptions({
  1. Duration timeout = const Duration(seconds: 30),
})

Handles exceptions that occur during the request.

Implementation

Future<http.Response> handleExceptions({
  final Duration timeout = const Duration(seconds: 30),
}) {
  return this
      .timeout(
        timeout,
        onTimeout: () => http.Response.bytes(
          [],
          408,
          reasonPhrase: 'Timed out after ${timeout.inSeconds} seconds',
        ),
      )
      .catchError(
        (e) => http.Response.bytes(
          [],
          500,
          reasonPhrase: e.toString(),
        ),
      );
}