Skip to content

Commit

Permalink
handle error when creating and updating smart services; fix #SNRGY-3250
Browse files Browse the repository at this point in the history
  • Loading branch information
hahahannes committed Apr 19, 2024
1 parent 267e8dc commit 49775b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
30 changes: 25 additions & 5 deletions lib/widgets/tabs/smart-services/instance_edit_launch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'package:mobile_app/models/smart_service.dart';
import 'package:mobile_app/theme.dart';
import 'package:mobile_app/widgets/shared/delay_circular_progress_indicator.dart';
import 'package:mobile_app/widgets/shared/expandable_text.dart';
import 'package:mobile_app/widgets/shared/toast.dart';

class SmartServicesReleaseLaunch extends StatefulWidget {
final SmartServiceRelease release;
Expand Down Expand Up @@ -229,7 +230,14 @@ class _SmartServicesReleaseLaunchState extends State<SmartServicesReleaseLaunch>
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (widget.parameters == null) {
parameters = await SmartServiceService.getReleaseParameters(widget.release.id);
try {
parameters =
await SmartServiceService.getReleaseParameters(widget.release.id);
} catch (e) {
_logger.e("Could not load release parameters: $e");
Navigator.pop(context);
Toast.showToastNoContext("Could not load smart service release");
}
} else {
parameters = widget.parameters;
}
Expand Down Expand Up @@ -340,13 +348,25 @@ class _SmartServicesReleaseLaunchState extends State<SmartServicesReleaseLaunch>
});
if (nameDescription == null) return;

await SmartServiceService.createInstance(widget.release.id, parameters!.map((e) => e.toSmartServiceParameter()).toList(),
try {
await SmartServiceService.createInstance(widget.release.id, parameters!.map((e) => e.toSmartServiceParameter()).toList(),
nameDescription["name"], nameDescription["description"]);
} catch (e) {
_logger.e("Could not create smart service instance: $e");
Toast.showToastNoContext("Could not start smart service");
}
Navigator.pop(context);
} else {
await SmartServiceService.updateInstanceParameters(
widget.instance!.id, parameters!.map((e) => e.toSmartServiceParameter()).toList(),
releaseId: widget.release.id);
try {
await SmartServiceService.updateInstanceParameters(
widget.instance!.id,
parameters!.map((e) => e.toSmartServiceParameter())
.toList(),
releaseId: widget.release.id);
} catch (e) {
_logger.e("Could not update smart service instance: $e");
Toast.showToastNoContext("Could not update smart service");
}
}
Navigator.pop(this.context);
},
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 0.0.307+307
version: 0.0.308+308


environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down

0 comments on commit 49775b5

Please sign in to comment.