onResponse method
The callback will be executed on success.
If you want to continue the response, call handler.next
.
If you want to complete the response with some custom data directly,
you can resolve a Response object with handler.resolve
and other
response interceptor(s) will not be executed.
If you want to complete the response with an error message,
you can reject a DioError object with handler.reject
.
Implementation
@override
void onResponse(Response response, ResponseInterceptorHandler handler) {
_printResponseHeader(response);
if (responseHeader) {
final responseHeaders = <String, String>{};
response.headers
.forEach((k, list) => responseHeaders[k] = list.toString());
_printMapAsTable(responseHeaders, header: 'Headers');
}
if (responseBody) {
logPrint('╔ Body');
logPrint('║');
_printResponse(response);
logPrint('║');
_printLine('╚');
}
if (logEntry != null) {
// 添加响应信息到 logEntry
final updatedLogEntry = LogEntry(
requestMethod: logEntry!.requestMethod,
requestUri: logEntry!.requestUri,
requestHeaders: logEntry!.requestHeaders,
requestBody: logEntry!.requestBody,
statusCode: response.statusCode,
responseHeaders: response.headers.map,
responseBody: response.data,
timestamp: logEntry!.timestamp,
);
LackOff.addLog(LackOffBean(
logType: LogType.dio,
logTitle: logEntry?.requestUri.toString() ?? '',
logDetail: '${updatedLogEntry.toMap()},',
date: DateTime.now().toString(),
));
}
super.onResponse(response, handler);
}