Skip to content

Commit

Permalink
fix: better place for raising error, no need for try except in enqueue
Browse files Browse the repository at this point in the history
(cherry picked from commit dccca5d)
  • Loading branch information
vorasmit authored and mergify[bot] committed Sep 11, 2024
1 parent 46c8540 commit fcb9c8e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
28 changes: 14 additions & 14 deletions india_compliance/gst_india/api_classes/taxpayer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ def request_otp(self):

def autheticate_with_otp(self, otp=None):
if not otp:
# in enqueue / cron job
if getattr(frappe.local, "job", None):
frappe.local.job.after_job.add(self.reset_auth_token)
raise InvalidAuthTokenError

# reset auth token
frappe.db.set_value(
"GST Credential",
Expand All @@ -150,7 +155,7 @@ def autheticate_with_otp(self, otp=None):
self.auth_token = None
return self.request_otp()

return super().post(
response = super().post(
json={
"action": "AUTHTOKEN",
"app_key": self.app_key,
Expand All @@ -160,6 +165,14 @@ def autheticate_with_otp(self, otp=None):
endpoint="authenticate",
)

frappe.cache.set_value(
f"authenticated_gstin:{self.company_gstin}",
True,
expires_in_sec=60 * 15,
)

return response

def refresh_auth_token(self):
auth_token = self.get_auth_token()

Expand Down Expand Up @@ -317,12 +330,6 @@ def _request(
if response.error_type in ["otp_requested", "invalid_otp"]:
return response

frappe.cache.set_value(
f"authenticated_gstin:{self.company_gstin}",
True,
expires_in_sec=60 * 15,
)

headers = {"auth-token": auth_token}
if return_period:
headers["ret_period"] = return_period
Expand Down Expand Up @@ -407,13 +414,6 @@ def is_ignored_error(self, response):
if response.error_type == "invalid_otp":
raise InvalidOTPError(response=response)

if response.error_type == "authorization_failed" and getattr(
frappe.local, "job", None
):
frappe.local.job.after_job.add(self.reset_auth_token)

raise InvalidAuthTokenError

return True

def generate_app_key(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,23 +451,16 @@ def download_gstr(
force=False,
gst_categories=None,
):
try:
return_type = ReturnType(return_type)

if return_type == ReturnType.GSTR2A:
return download_pending_gstr_2a(
date_range, company_gstin, force, gst_categories
)
return_type = ReturnType(return_type)

if return_type == ReturnType.GSTR2B:
return download_pending_gstr_2b(date_range, company_gstin)

except Exception:
frappe.log_error(
frappe.get_traceback(),
f"Error while downloading {return_type.value if return_type else 'GSTR 2A & 2B'} for {company_gstin} ",
if return_type == ReturnType.GSTR2A:
return download_pending_gstr_2a(
date_range, company_gstin, force, gst_categories
)

if return_type == ReturnType.GSTR2B:
return download_pending_gstr_2b(date_range, company_gstin)


def download_pending_gstr_2a(
date_range, company_gstin, force=False, gst_categories=None
Expand Down

0 comments on commit fcb9c8e

Please sign in to comment.