Skip to content

Commit

Permalink
Merge pull request #2213 from resilient-tech/mergify/bp/version-14-ho…
Browse files Browse the repository at this point in the history
…tfix/pr-2209

fix: handle cases where public key is invalided (backport #2209)
  • Loading branch information
mergify[bot] authored Jun 7, 2024
2 parents 7b5de9d + 9c6c746 commit c681f41
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions india_compliance/gst_india/api_classes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def _make_request(
)

response_json = self.process_response(response_json)

if response_json.get("error_type") == "invalid_public_key":
return self._make_request(method, endpoint, params, headers, json)

return response_json.get("result", response_json)

except Exception as e:
Expand Down
15 changes: 14 additions & 1 deletion india_compliance/gst_india/api_classes/returns.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
class PublicCertificate(BaseAPI):
BASE_PATH = "static"

def get_gstn_public_certificate(self) -> str:
def get_gstn_public_certificate(self, error_message=None) -> str:
response = self.get(endpoint="gstn_g2b_prod_public")

if response.certificate == self.settings.gstn_public_certificate:
frappe.throw(error_message or _("Public Certificate is already up to date"))

self.settings.db_set("gstn_public_certificate", response.certificate)

return response.certificate
Expand Down Expand Up @@ -232,6 +236,7 @@ class ReturnsAPI(ReturnsAuthenticate):
"AUTH4038": "authorization_failed", # Session Expired
"RET11402": "authorization_failed", # API Authorization Failed for 2A
"RET2B1010": "authorization_failed", # API Authorization Failed for 2B
"TEC4002": "invalid_public_key",
}

def setup(self, company_gstin):
Expand Down Expand Up @@ -336,6 +341,14 @@ def handle_error_response(self, response):
title=_("API Request Failed"),
)

# Handle invalid public key
if response.error_type == "invalid_public_key":
PublicCertificate().get_gstn_public_certificate(
error_message=_(
"Looks like Public Key of GSTN used for encryption is Invalid"
)
)

def is_ignored_error(self, response):
error_code = response.get("error", {}).get("error_cd")

Expand Down

0 comments on commit c681f41

Please sign in to comment.