handle no-subscription error

This commit is contained in:
Neeraj Gupta 2022-01-24 16:19:47 +05:30
parent 89de4f8787
commit 1323091b58
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
2 changed files with 49 additions and 35 deletions

View file

@ -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;

View file

@ -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 {