Skip to content

Commit

Permalink
fix: fetchWithJsonError now handles cases where the resource is binary
Browse files Browse the repository at this point in the history
Previously, this would cause a forced cast to `String?` error.
  • Loading branch information
w568w committed Feb 26, 2025
1 parent 15813f0 commit 404340c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/util/io/dio_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class DioUtils {
/// (The original [fetch] will throw a [DioException] WITHOUT the response data when [FormatException] occurs.)
static Future<Response<T>> fetchWithJsonError<T>(
Dio dio, RequestOptions options) async {
if (T == dynamic || options.responseType == ResponseType.bytes || options.responseType == ResponseType.stream) {
// If T is dynamic, or the caller wants bytes or stream, just call the original fetch.
// Because we are going to parse the response data as [String] below!
return await dio.fetch(options) as Response<T>;
}

Response<String> response = await dio.fetch(options);
if (T == String) {
return response as Response<T>;
Expand Down

0 comments on commit 404340c

Please sign in to comment.