Skip to content

Commit

Permalink
fix: add support email
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanket322 committed May 10, 2024
1 parent 204afed commit d4bafba
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
43 changes: 37 additions & 6 deletions india_compliance/gst_india/api_classes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import frappe
from frappe import _
from frappe.utils import sbool
from frappe.utils.change_log import get_versions

from india_compliance.exceptions import GatewayTimeoutError, GSPServerError
from india_compliance.gst_india.utils import is_api_enabled
Expand Down Expand Up @@ -138,7 +139,7 @@ def _make_request(
pass

# Raise special error for certain HTTP codes
self.handle_http_code(response.status_code, response_json)
self.handle_http_code(response.status_code, response_json, request_args)

# Raise HTTPError for other HTTP codes
response.raise_for_status()
Expand Down Expand Up @@ -216,22 +217,52 @@ def is_ignored_error(self, response_json):
# Override in subclass, return truthy value to stop frappe.throw
pass

def handle_http_code(self, status_code, response_json):
# TODO: add link to account page / support email
def handle_http_code(self, status_code, response_json, request_args):

# GSP connectivity issues
if status_code == 401 or (
status_code == 403
and response_json
and response_json.get("error") == "access_denied"
):
frappe.throw(
_("Error establishing connection to GSP. Please contact {0}.").format(

ic_api_key = frappe.conf.ic_api_key
if not ic_api_key:
request_data = {
"type": frappe.request.method,
"args": request_args.params or {},
"headers": request_args.headers or {},
"url": request_args.url,
}

app_version = {}
installed_apps_info = get_versions()
for app in installed_apps_info:
app_version[app] = installed_apps_info[app]["version"]

args = {
"app_version": app_version,
"response": response_json.message,
"request_data": request_data,
"traceback": frappe.get_traceback(),
}

frappe.msgprint(
msg=_(
"Error establishing connection to GSP. Please contact {0}."
).format(
_("your Service Provider")
if frappe.conf.ic_api_key
if ic_api_key
else _("India Compliance API Support")
),
title=_("GSP Connection Error"),
indicator="red",
raise_exception=frappe.ValidationError,
primary_action={
"label": "Send Email" if not ic_api_key else "Cancel",
"client_action": "india_compliance.show_communication",
"args": args if not ic_api_key else "Cancel",
},
)

# ASP connectivity issues
Expand Down
37 changes: 37 additions & 0 deletions india_compliance/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,43 @@ Object.assign(india_compliance, {
is_authenticated = true;
return true;
}
},
show_communication:(args) => {

frappe.ui.hide_open_dialog()

if(args == "Cancel")
return;

var error_report_message = [
"<h5>Please type some additional information that could help us reproduce this issue:</h5>",
'<div style="min-height: 100px; border: 1px solid #bbb; \
border-radius: 5px; padding: 15px; margin-bottom: 15px;"></div>',
"<hr>",
"<h5>App Versions</h5>",
"<pre>" + JSON.stringify(args.app_version) + "</pre>",
"<h5>Route</h5>",
"<pre>" + "frappe.get_route_str()" +"</pre>",
"<hr>",
"<h5>Error Report</h5>",
"<pre>" + JSON.stringify(args.traceback) + "</pre>",
"<hr>",
"<h5>Request Data</h5>",
"<pre>" + JSON.stringify(args.request_data) + "</pre>",
"<hr>",
"<h5>Response JSON</h5>",
"<pre>" + JSON.stringify(args.response) + "</pre>",
].join("\n");

var communication_composer = new frappe.views.CommunicationComposer({
subject: "Error Report [" + frappe.datetime.nowdate() + "]",
recipients: "",
message: error_report_message,
doc: {
doctype: "User",
name: frappe.session.user,
},
});
}
});

Expand Down

0 comments on commit d4bafba

Please sign in to comment.