fix(logs): Implement json encode error handling

- Resolves: #569
This commit is contained in:
NaiJi 2024-08-26 10:22:11 +04:00
parent b0fa29e13e
commit de3503250c

View file

@ -101,12 +101,19 @@ class ConsoleInterceptor extends InterceptorsWrapper {
) async {
final Response? response = err.response;
String responseEncoded = '';
try {
responseEncoded = jsonEncode(response);
} catch (e) {
responseEncoded = response?.statusMessage ?? responseEncoded;
}
addConsoleLog(
ManualConsoleLog.warning(
customTitle: 'RestAPI error',
content: '"uri": "${response?.realUri}",\n'
'"status_code": ${response?.statusCode},\n'
'"response": ${jsonEncode(response)}',
'"response": $responseEncoded',
),
);
return super.onError(err, handler);