diff --git a/india_compliance/gst_india/api_classes/base.py b/india_compliance/gst_india/api_classes/base.py index a986497083..b61a2539b8 100644 --- a/india_compliance/gst_india/api_classes/base.py +++ b/india_compliance/gst_india/api_classes/base.py @@ -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: diff --git a/india_compliance/gst_india/api_classes/returns.py b/india_compliance/gst_india/api_classes/returns.py index 0b74c67b52..45ffd74ecd 100644 --- a/india_compliance/gst_india/api_classes/returns.py +++ b/india_compliance/gst_india/api_classes/returns.py @@ -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 @@ -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): @@ -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")