onResponse method
Called when the response is about to be resolved.
Implementation
@override
void onResponse(
Response<dynamic> response,
ResponseInterceptorHandler handler,
) {
try {
final String? id = response.requestOptions.extra[_extraKey] as String?;
if (id != null) {
final FFApiCall? existing = store
.getAll()
.cast<FFApiCall?>()
.firstWhere((FFApiCall? c) => c?.id == id, orElse: () => null);
if (existing != null) {
store.update(
existing.copyWith(
status: FFApiCallStatus.completed,
statusCode: response.statusCode,
responseBody: masker.maskBody(response.data),
responseHeaders: <String, Object?>{
for (final MapEntry<String, List<String>> e
in response.headers.map.entries)
e.key: e.value.join(', '),
},
responseTime: DateTime.now(),
),
);
}
}
FFLogger.debug(
'← ${response.statusCode} ${response.requestOptions.uri}',
tag: 'api',
);
} catch (e, st) {
FFLogger.warning('FFApiInterceptor.onResponse failed: $e', tag: 'api');
FFLogger.debug(st.toString(), tag: 'api');
}
handler.next(response);
}