From 8039283f3725d5e87466a5b69a9846e460b80cf1 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Thu, 15 Sep 2022 16:05:23 +0300 Subject: [PATCH] Wrap get metrics endpoint with try-catch --- .../server_providers/hetzner/hetzner.dart | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart b/lib/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart index 04ded55f..8340676d 100644 --- a/lib/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart +++ b/lib/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart @@ -466,19 +466,27 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi { ) async { final ServerHostingDetails? hetznerServer = getIt().serverDetails; - final Dio client = await getClient(); - final Map queryParameters = { - 'start': start.toUtc().toIso8601String(), - 'end': end.toUtc().toIso8601String(), - 'type': type - }; - final Response res = await client.get( - '/servers/${hetznerServer!.id}/metrics', - queryParameters: queryParameters, - ); - close(client); - return res.data; + Map metrics = {}; + final Dio client = await getClient(); + try { + final Map queryParameters = { + 'start': start.toUtc().toIso8601String(), + 'end': end.toUtc().toIso8601String(), + 'type': type + }; + final Response res = await client.get( + '/servers/${hetznerServer!.id}/metrics', + queryParameters: queryParameters, + ); + metrics = res.data; + } catch (e) { + print(e); + } finally { + close(client); + } + + return metrics; } Future getInfo() async {