From e26dfcf27151b28b5b20b23c1a8b853c0d1a0a17 Mon Sep 17 00:00:00 2001 From: TZ Date: Wed, 24 Apr 2024 10:29:55 +0200 Subject: [PATCH] catch smart service repo error when editing a release --- lib/services/app_update.dart | 2 +- lib/services/aspects.dart | 2 +- lib/services/characteristics.dart | 2 +- lib/services/concepts.dart | 2 +- lib/services/device_classes.dart | 2 +- lib/services/device_groups.dart | 10 ++--- lib/services/device_types.dart | 2 +- lib/services/device_types_perm_search.dart | 2 +- lib/services/devices.dart | 6 +-- lib/services/fcm_token.dart | 2 +- lib/services/functions.dart | 2 +- lib/services/locations.dart | 8 ++-- lib/services/mgw/auth.dart | 8 ++-- lib/services/mgw/error.dart | 2 +- lib/services/mgw/restricted.dart | 4 +- lib/services/networks.dart | 2 +- lib/services/notifications.dart | 2 +- lib/services/smart_service.dart | 18 ++++----- .../tabs/smart-services/instance_details.dart | 38 ++++++++++--------- 19 files changed, 60 insertions(+), 56 deletions(-) diff --git a/lib/services/app_update.dart b/lib/services/app_update.dart index 73788ce..6ae585d 100644 --- a/lib/services/app_update.dart +++ b/lib/services/app_update.dart @@ -144,7 +144,7 @@ class AppUpdater { final Response> resp; try { resp = await dio.get>(url); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { UnexpectedStatusCodeException( e.response?.statusCode, "$url ${e.message}"); // for logging diff --git a/lib/services/aspects.dart b/lib/services/aspects.dart index 227e302..f6647d6 100644 --- a/lib/services/aspects.dart +++ b/lib/services/aspects.dart @@ -67,7 +67,7 @@ class AspectsService { final Response?> resp; try { resp = await dio.get?>(uri); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); diff --git a/lib/services/characteristics.dart b/lib/services/characteristics.dart index ce1d973..5efbf00 100644 --- a/lib/services/characteristics.dart +++ b/lib/services/characteristics.dart @@ -79,7 +79,7 @@ class CharacteristicsService { resp = await dio.get?>(uri, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); diff --git a/lib/services/concepts.dart b/lib/services/concepts.dart index 364c6a3..25c47a8 100644 --- a/lib/services/concepts.dart +++ b/lib/services/concepts.dart @@ -79,7 +79,7 @@ class ConceptsService { resp = await dio.get?>(uri, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); diff --git a/lib/services/device_classes.dart b/lib/services/device_classes.dart index 27d173e..0d4eafa 100644 --- a/lib/services/device_classes.dart +++ b/lib/services/device_classes.dart @@ -69,7 +69,7 @@ class DeviceClassesService { try { resp = await dio.get?>(uri, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); diff --git a/lib/services/device_groups.dart b/lib/services/device_groups.dart index a7f6bfd..b3975e6 100644 --- a/lib/services/device_groups.dart +++ b/lib/services/device_groups.dart @@ -87,7 +87,7 @@ class DeviceGroupsService { try { resp = await _dio!.get?>(uri, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); @@ -142,7 +142,7 @@ class DeviceGroupsService { try { resp = await _dio!.put>(uri, options: Options(headers: headers), data: encoded); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); @@ -176,7 +176,7 @@ class DeviceGroupsService { resp = await dio.post(uri, options: Options(headers: headers), data: DeviceGroup("", name, [], "", [], []).toJson()); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); @@ -205,7 +205,7 @@ class DeviceGroupsService { ..httpClientAdapter = AppHttpClientAdapter(); try { await dio.delete(uri, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); @@ -242,7 +242,7 @@ class DeviceGroupsService { queryParameters: queryParameters, options: Options(headers: headers), data: json.encode(deviceIds)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); diff --git a/lib/services/device_types.dart b/lib/services/device_types.dart index 7aee1a9..eea14ff 100644 --- a/lib/services/device_types.dart +++ b/lib/services/device_types.dart @@ -75,7 +75,7 @@ class DeviceTypesService { final Response> resp; try { resp = await _dio!.get>(url, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } diff --git a/lib/services/device_types_perm_search.dart b/lib/services/device_types_perm_search.dart index 6fc0245..d7f2de2 100644 --- a/lib/services/device_types_perm_search.dart +++ b/lib/services/device_types_perm_search.dart @@ -74,7 +74,7 @@ class DeviceTypesPermSearchService { try { resp = await dio.get?>(uri, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); diff --git a/lib/services/devices.dart b/lib/services/devices.dart index 26a0d96..d4f0207 100644 --- a/lib/services/devices.dart +++ b/lib/services/devices.dart @@ -92,7 +92,7 @@ class DevicesService { resp = await _dio!.post?>( uri, options: Options(headers: headers), data: encoded); _logger.d("getDevices ${DateTime.now().difference(start)}"); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); @@ -132,7 +132,7 @@ class DevicesService { try { await _dio!.put( uri, options: Options(headers: headers), data: encoded); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); @@ -174,7 +174,7 @@ class DevicesService { resp = await _dio!.get(uri, options: Options(headers: headers), queryParameters: queryParameters); _logger.d("getTotalDevices ${DateTime.now().difference(start)}"); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); diff --git a/lib/services/fcm_token.dart b/lib/services/fcm_token.dart index 0b3aeb0..450807d 100644 --- a/lib/services/fcm_token.dart +++ b/lib/services/fcm_token.dart @@ -69,7 +69,7 @@ class FcmTokenService { final Response resp; try { resp = await _dio!.post(url, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } diff --git a/lib/services/functions.dart b/lib/services/functions.dart index f1afb26..01a823d 100644 --- a/lib/services/functions.dart +++ b/lib/services/functions.dart @@ -66,7 +66,7 @@ class FunctionsService { try { resp = await dio.get?>(uri, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException( e.response?.statusCode, "$uri ${e.message}"); diff --git a/lib/services/locations.dart b/lib/services/locations.dart index 00cd8d3..cb61125 100644 --- a/lib/services/locations.dart +++ b/lib/services/locations.dart @@ -74,7 +74,7 @@ class LocationService { final Response?> resp; try { resp = await _dio.get?>(uri, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$uri ${e.message}"); } @@ -102,7 +102,7 @@ class LocationService { final Response resp; try { resp = await _dio.put(uri, options: Options(headers: headers), data: location.toJson()); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$uri ${e.message}"); } @@ -126,7 +126,7 @@ class LocationService { final Response resp; try { resp = await _dio.post(uri, options: Options(headers: headers), data: Location("", name, "", "", [], []).toJson()); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$uri ${e.message}"); } @@ -148,7 +148,7 @@ class LocationService { await initOptions(); try { await _dio.delete(uri, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$uri ${e.message}"); } diff --git a/lib/services/mgw/auth.dart b/lib/services/mgw/auth.dart index 195cd2e..a3edc10 100644 --- a/lib/services/mgw/auth.dart +++ b/lib/services/mgw/auth.dart @@ -75,9 +75,9 @@ class MgwAuth { Response> resp; try { resp = await dio.post>(baseUrl + loginPath + "?refresh=true&flow=" + flowId, data: payload, options: Options(contentType: Headers.jsonContentType)); - } on DioError catch (e) { + } on DioException catch (e) { _logger.e(LOG_PREFIX + ": Could not login"); - var failure = handleDioError(e); + var failure = handleDioException(e); throw(failure); }; @@ -93,9 +93,9 @@ class MgwAuth { try { resp = await dio.get>(baseUrl + loginPath + "/api"); - } on DioError catch (e) { + } on DioException catch (e) { _logger.e(LOG_PREFIX + ": Could not init login"); - var failure = handleDioError(e); + var failure = handleDioException(e); throw(failure); }; diff --git a/lib/services/mgw/error.dart b/lib/services/mgw/error.dart index 79148af..c0574bc 100644 --- a/lib/services/mgw/error.dart +++ b/lib/services/mgw/error.dart @@ -27,7 +27,7 @@ enum ErrorCode { DEFAULT } -Failure handleDioError(DioException error) { +Failure handleDioException(DioException error) { final _logger = Logger( printer: SimplePrinter(), ); diff --git a/lib/services/mgw/restricted.dart b/lib/services/mgw/restricted.dart index 7951617..b681514 100644 --- a/lib/services/mgw/restricted.dart +++ b/lib/services/mgw/restricted.dart @@ -120,7 +120,7 @@ class MgwService { return resp; } on DioException catch (e) { _logger.e("$LOG_PREFIX: Request error: $e"); - var failure = handleDioError(e); + var failure = handleDioException(e); throw(failure); } } @@ -134,7 +134,7 @@ class MgwService { return resp; } on DioException catch (e) { _logger.e("$LOG_PREFIX: Get: Request error"); - var failure = handleDioError(e); + var failure = handleDioException(e); throw(failure); } } diff --git a/lib/services/networks.dart b/lib/services/networks.dart index 232221e..413d692 100644 --- a/lib/services/networks.dart +++ b/lib/services/networks.dart @@ -77,7 +77,7 @@ class NetworksService { final Response?> resp; try { resp = await dio.get?>(uri, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$uri ${e.message}"); } diff --git a/lib/services/notifications.dart b/lib/services/notifications.dart index 9650627..df549b9 100644 --- a/lib/services/notifications.dart +++ b/lib/services/notifications.dart @@ -71,7 +71,7 @@ class NotificationsService { final Response> resp; try { resp = await _dio!.get>(uri, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$uri ${e.message}"); } diff --git a/lib/services/smart_service.dart b/lib/services/smart_service.dart index 91bfaf2..65b2e3b 100644 --- a/lib/services/smart_service.dart +++ b/lib/services/smart_service.dart @@ -72,7 +72,7 @@ class SmartServiceService { final Response resp; try { resp = await _dio.get(url, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } @@ -96,7 +96,7 @@ class SmartServiceService { final Response?> resp; try { resp = await _dio.get?>(url, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } @@ -117,7 +117,7 @@ class SmartServiceService { await initOptions(); try { await _dio.delete(url, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } @@ -142,7 +142,7 @@ class SmartServiceService { final Response resp; try { resp = await _dio.post(url, options: Options(headers: headers), data: json.encode(body)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } @@ -165,7 +165,7 @@ class SmartServiceService { final Response resp; try { resp = await _dio.put(url, queryParameters: queryParameters, options: Options(headers: headers), data: json.encode(parameters)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } @@ -187,7 +187,7 @@ class SmartServiceService { final Response resp; try { resp = await _dio.put(url, options: Options(headers: headers), data: json.encode(body)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 299) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } @@ -235,7 +235,7 @@ class SmartServiceService { final Response?> resp; try { resp = await _dio.get?>(url, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } @@ -257,7 +257,7 @@ class SmartServiceService { final Response resp; try { resp = await _dio.get(url, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } @@ -286,7 +286,7 @@ class SmartServiceService { final Response?> resp; try { resp = await _dio.get?>(url, queryParameters: queryParameters, options: Options(headers: headers)); - } on DioError catch (e) { + } on DioException catch (e) { if (e.response?.statusCode == null || e.response!.statusCode! > 304) { throw UnexpectedStatusCodeException(e.response?.statusCode, "$url ${e.message}"); } diff --git a/lib/widgets/tabs/smart-services/instance_details.dart b/lib/widgets/tabs/smart-services/instance_details.dart index 7301efc..fc3e63d 100644 --- a/lib/widgets/tabs/smart-services/instance_details.dart +++ b/lib/widgets/tabs/smart-services/instance_details.dart @@ -82,24 +82,28 @@ class _SmartServicesInstanceDetailsState extends State p.id == extisting.id); - p.value = existing.value; - p.value_label = existing.value_label; + try { + final release = await SmartServiceService.getRelease(widget.instance.release_id); + final parameters = await SmartServiceService.getReleaseParameters(widget.instance.release_id); + for (SmartServiceExtendedParameter p in parameters) { + final existing = widget.instance.parameters!.firstWhere((extisting) => p.id == extisting.id); + p.value = existing.value; + p.value_label = existing.value_label; + } + await Navigator.push( + this.context, + platformPageRoute( + context: this.context, + builder: (_) => SmartServicesReleaseLaunch( + release, + instance: widget.instance, + parameters: parameters, + ), + )); + Navigator.pop(this.context); + } catch (e) { + Toast.showToastNoContext(e.toString()); } - await Navigator.push( - this.context, - platformPageRoute( - context: this.context, - builder: (_) => SmartServicesReleaseLaunch( - release, - instance: widget.instance, - parameters: parameters, - ), - )); - Navigator.pop(this.context); }, backgroundColor: MyTheme.appColor, child: Icon(Icons.edit, color: MyTheme.textColor),