From 791182d9c40a7c08ac5dc8b9874b080324066d4f Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Thu, 23 Nov 2023 10:29:21 +0100 Subject: [PATCH] Fix format exception getServerStatus --- lib/services/api_client.dart | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/services/api_client.dart b/lib/services/api_client.dart index d8ef244..d99ab7c 100644 --- a/lib/services/api_client.dart +++ b/lib/services/api_client.dart @@ -59,24 +59,30 @@ class ApiClientV2 { HttpRequestClient.get(urlPath: "/parental/status", server: server), HttpRequestClient.get(urlPath: "/clients", server: server), ]); - if ( results.map((e) => e.successful).every((e) => e == true) && results.map((e) => e.body).every((e) => e != null) ) { - final Map mappedData = { - 'stats': jsonDecode(results[0].body!), - 'clients': jsonDecode(results[6].body!)['clients'], - 'status': jsonDecode(results[1].body!), - 'filtering': jsonDecode(results[2].body!), - 'safeSearch': jsonDecode(results[3].body!), - 'safeBrowsingEnabled': jsonDecode(results[4].body!), - 'parentalControlEnabled': jsonDecode(results[5].body!), - }; - return ApiResponse( - successful: true, - content: ServerStatus.fromJson(mappedData) - ); + try { + final Map mappedData = { + 'stats': jsonDecode(results[0].body!), + 'clients': jsonDecode(results[6].body!)['clients'], + 'status': jsonDecode(results[1].body!), + 'filtering': jsonDecode(results[2].body!), + 'safeSearch': jsonDecode(results[3].body!), + 'safeBrowsingEnabled': jsonDecode(results[4].body!), + 'parentalControlEnabled': jsonDecode(results[5].body!), + }; + return ApiResponse( + successful: true, + content: ServerStatus.fromJson(mappedData) + ); + } on FormatException { + return const ApiResponse(successful: false); + } catch (e, stackTrace) { + Sentry.captureException(e, stackTrace: stackTrace); + return const ApiResponse(successful: false); + } } else { return const ApiResponse(successful: false);