From 52d210974b23b2d883aad7ae2f62cf77311026b8 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 15 Mar 2025 18:34:49 -0500 Subject: [PATCH] display error if mount location is not found --- web/repertory/lib/models/mount.dart | 13 ++++++++++--- web/repertory/lib/widgets/mount_widget.dart | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/web/repertory/lib/models/mount.dart b/web/repertory/lib/models/mount.dart index 87c31d51..58e2fc8b 100644 --- a/web/repertory/lib/models/mount.dart +++ b/web/repertory/lib/models/mount.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; +import 'package:repertory/constants.dart' as constants; import 'package:repertory/helpers.dart'; import 'package:repertory/models/mount_list.dart'; import 'package:repertory/types/mount_config.dart'; @@ -73,9 +74,9 @@ class Mount with ChangeNotifier { } } - Future mount(bool unmount, {String? location}) async { + Future mount(bool unmount, {String? location}) async { try { - await http.post( + final response = await http.post( Uri.parse( Uri.encodeFull( '${getBaseUri()}/api/v1/mount?unmount=$unmount&name=$name&type=$type&location=$location', @@ -83,10 +84,16 @@ class Mount with ChangeNotifier { ), ); - return refresh(); + if (response.statusCode == 500) { + return false; + } + + await refresh(); } catch (e) { debugPrint('$e'); } + + return true; } Future refresh() async { diff --git a/web/repertory/lib/widgets/mount_widget.dart b/web/repertory/lib/widgets/mount_widget.dart index 5f33d124..bdca5ef7 100644 --- a/web/repertory/lib/widgets/mount_widget.dart +++ b/web/repertory/lib/widgets/mount_widget.dart @@ -158,10 +158,23 @@ class _MountWidgetState extends State { mount .mount(isActive, location: location) - .then((_) { + .then((success) { setState(() { _enabled = true; }); + + if (isActive || !context.mounted) { + return; + } + + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: const Text( + "Mount location not found", + textAlign: TextAlign.center, + ), + ), + ); }) .catchError((_) { setState(() {