handle no-subscription error
This commit is contained in:
parent
89de4f8787
commit
1323091b58
|
@ -286,6 +286,11 @@ class CollectionsService {
|
|||
collection.publicURLs?.add(PublicURL.fromMap(response.data["result"]));
|
||||
await _db.insert(List.from([collection]));
|
||||
_cacheCollectionAttributes(collection);
|
||||
} on DioError catch (e) {
|
||||
if (e.response.statusCode == 402) {
|
||||
throw SharingNotPermittedForFreeAccountsError();
|
||||
}
|
||||
rethrow;
|
||||
} catch (e, s) {
|
||||
_logger.severe("failed to rename collection", e, s);
|
||||
rethrow;
|
||||
|
|
|
@ -110,11 +110,16 @@ class _SharingDialogState extends State<SharingDialog> {
|
|||
: await CollectionsService.instance
|
||||
.disableShareUrl(widget.collection);
|
||||
} catch (e) {
|
||||
_logger.severe('failed to $enable url', e);
|
||||
} finally {
|
||||
dialog.hide();
|
||||
setState(() {});
|
||||
if (e is SharingNotPermittedForFreeAccountsError) {
|
||||
_showUnSupportedAlert();
|
||||
} else {
|
||||
_logger.severe("failed to share collection", e);
|
||||
showGenericErrorDialog(context);
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -320,38 +325,7 @@ class _SharingDialogState extends State<SharingDialog> {
|
|||
} catch (e) {
|
||||
await dialog.hide();
|
||||
if (e is SharingNotPermittedForFreeAccountsError) {
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text("sorry"),
|
||||
content: Text(
|
||||
"sharing is not permitted for free accounts, please subscribe"),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text("subscribe"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return getSubscriptionPage();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text("ok"),
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
_showUnSupportedAlert();
|
||||
} else {
|
||||
_logger.severe("failed to share collection", e);
|
||||
showGenericErrorDialog(context);
|
||||
|
@ -359,6 +333,41 @@ class _SharingDialogState extends State<SharingDialog> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _showUnSupportedAlert() {
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text("sorry"),
|
||||
content:
|
||||
Text("sharing is not permitted for free accounts, please subscribe"),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text("subscribe"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return getSubscriptionPage();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text("ok"),
|
||||
onPressed: () {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EmailItemWidget extends StatelessWidget {
|
||||
|
|
Loading…
Reference in a new issue