ResponseValidator typedef

ResponseValidator = ApiException? Function(Response response)

A callback that inspects a successful (2xx) response and either returns null to let it pass through, or returns an ApiException subclass to have the request fail with that exception.

Useful for legacy APIs that signal business errors via 200-OK responses with a payload like {"success": false, "error": "..."}.

It sees every 2xx response, including binary downloads, whose response.data is a Uint8List. A validator written for JSON envelopes should let what it does not understand through — otherwise each download fails with responseValidator threw:

responseValidator: (response) {
  final data = response.data;
  if (data is! Map) return null;
  return data['success'] == false ? BusinessException(data) : null;
},

Implementation

typedef ResponseValidator = ApiException? Function(
  Response<dynamic> response,
);