Skip to content

Commit

Permalink
catch smart service repo error when editing a release
Browse files Browse the repository at this point in the history
  • Loading branch information
zsco committed Apr 24, 2024
1 parent b23b15a commit e26dfcf
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 56 deletions.
2 changes: 1 addition & 1 deletion lib/services/app_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class AppUpdater {
final Response<List<dynamic>> resp;
try {
resp = await dio.get<List<dynamic>>(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
Expand Down
2 changes: 1 addition & 1 deletion lib/services/aspects.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AspectsService {
final Response<List<dynamic>?> resp;
try {
resp = await dio.get<List<dynamic>?>(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}");
Expand Down
2 changes: 1 addition & 1 deletion lib/services/characteristics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CharacteristicsService {
resp = await dio.get<List<dynamic>?>(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}");
Expand Down
2 changes: 1 addition & 1 deletion lib/services/concepts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ConceptsService {
resp = await dio.get<List<dynamic>?>(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}");
Expand Down
2 changes: 1 addition & 1 deletion lib/services/device_classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class DeviceClassesService {
try {
resp = await dio.get<Map<String, dynamic>?>(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}");
Expand Down
10 changes: 5 additions & 5 deletions lib/services/device_groups.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class DeviceGroupsService {
try {
resp = await _dio!.get<List<dynamic>?>(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}");
Expand Down Expand Up @@ -142,7 +142,7 @@ class DeviceGroupsService {
try {
resp = await _dio!.put<Map<String, dynamic>>(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}");
Expand Down Expand Up @@ -176,7 +176,7 @@ class DeviceGroupsService {
resp = await dio.post<dynamic>(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}");
Expand Down Expand Up @@ -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}");
Expand Down Expand Up @@ -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}");
Expand Down
2 changes: 1 addition & 1 deletion lib/services/device_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DeviceTypesService {
final Response<Map<String, dynamic>> resp;
try {
resp = await _dio!.get<Map<String, dynamic>>(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}");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/device_types_perm_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DeviceTypesPermSearchService {
try {
resp = await dio.get<List<dynamic>?>(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}");
Expand Down
6 changes: 3 additions & 3 deletions lib/services/devices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class DevicesService {
resp = await _dio!.post<List<dynamic>?>(
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}");
Expand Down Expand Up @@ -132,7 +132,7 @@ class DevicesService {
try {
await _dio!.put<dynamic>(
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}");
Expand Down Expand Up @@ -174,7 +174,7 @@ class DevicesService {
resp = await _dio!.get<int>(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}");
Expand Down
2 changes: 1 addition & 1 deletion lib/services/fcm_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FunctionsService {
try {
resp = await dio.get<List<dynamic>?>(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}");
Expand Down
8 changes: 4 additions & 4 deletions lib/services/locations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class LocationService {
final Response<List<dynamic>?> resp;
try {
resp = await _dio.get<List<dynamic>?>(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}");
}
Expand Down Expand Up @@ -102,7 +102,7 @@ class LocationService {
final Response<dynamic> resp;
try {
resp = await _dio.put<dynamic>(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}");
}
Expand All @@ -126,7 +126,7 @@ class LocationService {
final Response<dynamic> resp;
try {
resp = await _dio.post<dynamic>(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}");
}
Expand All @@ -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}");
}
Expand Down
8 changes: 4 additions & 4 deletions lib/services/mgw/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class MgwAuth {
Response<Map<String, dynamic>> resp;
try {
resp = await dio.post<Map<String, dynamic>>(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);
};

Expand All @@ -93,9 +93,9 @@ class MgwAuth {

try {
resp = await dio.get<Map<String, dynamic>>(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);
};

Expand Down
2 changes: 1 addition & 1 deletion lib/services/mgw/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum ErrorCode {
DEFAULT
}

Failure handleDioError(DioException error) {
Failure handleDioException(DioException error) {
final _logger = Logger(
printer: SimplePrinter(),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/services/mgw/restricted.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/networks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class NetworksService {
final Response<List<dynamic>?> resp;
try {
resp = await dio.get<List<dynamic>?>(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}");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/services/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NotificationsService {
final Response<Map<String, dynamic>> resp;
try {
resp = await _dio!.get<Map<String, dynamic>>(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}");
}
Expand Down
18 changes: 9 additions & 9 deletions lib/services/smart_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SmartServiceService {
final Response<dynamic> resp;
try {
resp = await _dio.get<dynamic>(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}");
}
Expand All @@ -96,7 +96,7 @@ class SmartServiceService {
final Response<List<dynamic>?> resp;
try {
resp = await _dio.get<List<dynamic>?>(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}");
}
Expand All @@ -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}");
}
Expand All @@ -142,7 +142,7 @@ class SmartServiceService {
final Response<dynamic> resp;
try {
resp = await _dio.post<dynamic>(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}");
}
Expand All @@ -165,7 +165,7 @@ class SmartServiceService {
final Response<dynamic> resp;
try {
resp = await _dio.put<dynamic>(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}");
}
Expand All @@ -187,7 +187,7 @@ class SmartServiceService {
final Response<dynamic> resp;
try {
resp = await _dio.put<dynamic>(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}");
}
Expand Down Expand Up @@ -235,7 +235,7 @@ class SmartServiceService {
final Response<List<dynamic>?> resp;
try {
resp = await _dio.get<List<dynamic>?>(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}");
}
Expand All @@ -257,7 +257,7 @@ class SmartServiceService {
final Response<dynamic> resp;
try {
resp = await _dio.get<dynamic>(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}");
}
Expand Down Expand Up @@ -286,7 +286,7 @@ class SmartServiceService {
final Response<List<dynamic>?> resp;
try {
resp = await _dio.get<List<dynamic>?>(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}");
}
Expand Down
38 changes: 21 additions & 17 deletions lib/widgets/tabs/smart-services/instance_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,28 @@ class _SmartServicesInstanceDetailsState extends State<SmartServicesInstanceDeta
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () async {
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;
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),
Expand Down

0 comments on commit e26dfcf

Please sign in to comment.