From de3503250c47308098263cb5cc8fc1c16712012d Mon Sep 17 00:00:00 2001 From: NaiJi Date: Mon, 26 Aug 2024 10:22:11 +0400 Subject: [PATCH] fix(logs): Implement json encode error handling - Resolves: #569 --- lib/logic/api_maps/rest_maps/rest_api_map.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/logic/api_maps/rest_maps/rest_api_map.dart b/lib/logic/api_maps/rest_maps/rest_api_map.dart index 6501a7de..a4c30991 100644 --- a/lib/logic/api_maps/rest_maps/rest_api_map.dart +++ b/lib/logic/api_maps/rest_maps/rest_api_map.dart @@ -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);