logResponse function
void
logResponse(
- Result result
)
Implementation
void logResponse(Result result) {
if (result.error != null) {
logWarning("""
\n->->->->->->->->->->Response->->->->->->->->->
[URL] ${result.requestOptions?.uri}
----------------------${result.response?.statusCode}------------------->
[Error] ${result.error}: ${result.message}
->->->->->->->->->->Response->->->->->->->->->
""");
return;
}
var string = """
\n->->->->->->->->->->Response->->->->->->->->->
[URL] ${result.response?.requestOptions.uri}
[Method] ${result.response?.requestOptions.method}
[ConnectTimeout] ${result.response?.requestOptions.connectTimeout}
[ReceiveTimeout] ${result.response?.requestOptions.receiveTimeout}
[FollowRedirects] ${result.response?.requestOptions.followRedirects}
""";
if (result.response?.requestOptions.headers != null &&
!result.response!.requestOptions.headers.isEmptyOrNull) {
string += """
[Header]
${jsonEncode(result.response?.requestOptions.headers)}
""";
}
if (result.response?.requestOptions.extra != null &&
!result.response!.requestOptions.extra.isEmptyOrNull) {
string += """
[Extra]
${jsonEncode(result.response?.requestOptions.extra)}
""";
}
if (result.response?.requestOptions.data != null) {
string += """
[Body]
${result.response?.requestOptions.data is Map ? jsonEncode(result.response?.requestOptions.data) : result.response?.requestOptions.data}
""";
}
string +=
"----------------------${result.response?.statusCode}------------------->";
if (result.response?.headers != null &&
!result.response!.headers.isEmptyOrNull) {
string += """
\n[Header]
${result.response?.headers}
""";
}
if (result.response?.extra != null && !result.response!.extra.isEmptyOrNull) {
string += """
[Extra]
${jsonEncode(result.response?.extra)}
""";
}
if (result.response?.data != null) {
string += """
[Data]
${result.response?.data is Map ? jsonEncode(result.response?.data) : result.response?.data}
""";
}
string += "->->->->->->->->->->Response->->->->->->->->->";
logInfo(string);
}