Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific "paid plan required" error message #93

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions felt/core/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class CreatedGroupDetails:
ordering_key: Optional[int] = None


class PaidPlanRequiredError(Exception):
"""Raised when an API operation requires a paid plan"""
pass


class FeltApiClient:
"""
Client for the Felt API
Expand Down Expand Up @@ -512,6 +517,9 @@ def create_layer_groups(self,
json.dumps(group_post_data).encode()
)

if reply.error() == QNetworkReply.ContentAccessDenied:
raise PaidPlanRequiredError("Upload requires a paid plan")

return [
CreatedGroupDetails(
group_id=group['id'],
Expand Down
42 changes: 31 additions & 11 deletions felt/core/map_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
from qgis.utils import iface

from .api_client import API_CLIENT
from .api_client import API_CLIENT, PaidPlanRequiredError
from .enums import LayerSupport
from .exceptions import LayerPackagingException
from .layer_exporter import LayerExporter
Expand Down Expand Up @@ -279,6 +279,7 @@ def __init__(self,
self.error_string: Optional[str] = None
self.feedback: Optional[QgsFeedback] = None
self.was_canceled = False
self.paid_plan_error = False

@staticmethod
def layer_and_group(
Expand Down Expand Up @@ -507,6 +508,8 @@ def run(self):
)

if reply.error() != QNetworkReply.NoError:
if reply.error() == QNetworkReply.ContentAccessDenied:
self.paid_plan_error = True
self.error_string = reply.errorString()
Logger.instance().log_error_json(
{
Expand Down Expand Up @@ -604,15 +607,27 @@ def run(self):
all_group_ordering_keys = self.project_structure.group_ordering_keys()
if all_group_ordering_keys:
# ensure group names match their order in the QGIS project
created_groups = API_CLIENT.create_layer_groups(
map_id=self.associated_map.id,
layer_group_names=list(all_group_ordering_keys.keys()),
ordering_keys=all_group_ordering_keys
)
created_group_details = {
group.name: group
for group in created_groups
}
try:
created_groups = API_CLIENT.create_layer_groups(
map_id=self.associated_map.id,
layer_group_names=list(all_group_ordering_keys.keys()),
ordering_keys=all_group_ordering_keys
)
created_group_details = {
group.name: group
for group in created_groups
}
except PaidPlanRequiredError:
self.paid_plan_error = True
self.error_string = 'Paid plan required for layer groups'
Logger.instance().log_error_json(
{
'type': Logger.MAP_EXPORT,
'error': 'Error creating layer groups: {}'.format(
self.error_string)
}
)
return False
else:
created_group_details = {}

Expand Down Expand Up @@ -655,6 +670,8 @@ def run(self):
continue

if reply.error() != QNetworkReply.NoError:
if reply.error() == QNetworkReply.ContentAccessDenied:
self.paid_plan_error = True
self.error_string = reply.errorString()
Logger.instance().log_error_json(
{
Expand All @@ -663,7 +680,6 @@ def run(self):
self.error_string)
}
)

return False
break

Expand Down Expand Up @@ -769,6 +785,8 @@ def _upload_progress(sent, total):
)

if reply and reply.error() != QNetworkReply.NoError:
if reply.error() == QNetworkReply.ContentAccessDenied:
self.paid_plan_error = True
self.error_string = reply.errorString()
Logger.instance().log_error_json(
{
Expand Down Expand Up @@ -806,6 +824,8 @@ def _upload_progress(sent, total):
)

if reply and reply.error() != QNetworkReply.NoError:
if reply.error() == QNetworkReply.ContentAccessDenied:
self.paid_plan_error = True
self.error_string = reply.errorString()
Logger.instance().log_error_json(
{
Expand Down
27 changes: 18 additions & 9 deletions felt/gui/create_map_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,16 +538,25 @@ def _upload_terminated(self):
self._map_title)
)

error_message = \
self.tr('There was an error uploading this file, please '
'contact <a href="mailto:[email protected]">'
'[email protected]</a> '
'for help fixing the issue')

if self.map_uploader_task.error_string:
error_message += '<p><b>{}</b></p>'.format(
self.map_uploader_task.error_string
if self.map_uploader_task.paid_plan_error:
error_message = self.tr(
'Uploading files to Felt requires a paid plan, '
'please visit '
'<a href=\'https://felt.com/pricing\'>felt.com/pricing</a>'
' or contact <a href=\'mailto:[email protected]\'>'
'[email protected]</a>.'
)
else:
error_message = \
self.tr('There was an error uploading this file, please '
'contact <a href="mailto:[email protected]">'
'[email protected]</a> '
'for help fixing the issue')

if self.map_uploader_task.error_string:
error_message += '<p><b>{}</b></p>'.format(
self.map_uploader_task.error_string
)

self.progress_label.setText(
GuiUtils.set_link_color(
Expand Down
Loading