fix(minor): update frappe.error_log to new API (#30864)

* fix(minor): update frappe.error_log to new API

* refactor: changes for updated log_error api

Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
Rushabh Mehta
2022-05-02 15:04:26 +05:30
committed by GitHub
parent dcda55641b
commit 548afba8bb
33 changed files with 59 additions and 97 deletions

View File

@@ -32,7 +32,7 @@ def order(*args, **kwargs):
error_message = (
frappe.get_traceback() + "\n\n Request Data: \n" + json.loads(frappe.request.data).__str__()
)
frappe.log_error(error_message, "WooCommerce Error")
frappe.log_error("WooCommerce Error", error_message)
raise

View File

@@ -107,7 +107,7 @@ class GoCardlessSettings(Document):
return self.create_charge_on_gocardless()
except Exception:
frappe.log_error(frappe.get_traceback())
frappe.log_error("Gocardless payment reqeust failed")
return {
"redirect_to": frappe.redirect_to_message(
_("Server Error"),
@@ -163,21 +163,15 @@ class GoCardlessSettings(Document):
or payment.status == "charged_back"
):
self.integration_request.db_set("status", "Cancelled", update_modified=False)
frappe.log_error(
_("Payment Cancelled. Please check your GoCardless Account for more details"),
"GoCardless Payment Error",
)
frappe.log_error("Gocardless payment cancelled")
self.integration_request.db_set("error", payment.status, update_modified=False)
else:
self.integration_request.db_set("status", "Failed", update_modified=False)
frappe.log_error(
_("Payment Failed. Please check your GoCardless Account for more details"),
"GoCardless Payment Error",
)
frappe.log_error("Gocardless payment failed")
self.integration_request.db_set("error", payment.status, update_modified=False)
except Exception as e:
frappe.log_error(e, "GoCardless Payment Error")
frappe.log_error("GoCardless Payment Error")
if self.flags.status_changed_to == "Completed":
status = "Completed"
@@ -188,7 +182,7 @@ class GoCardlessSettings(Document):
self.data.get("reference_doctype"), self.data.get("reference_docname")
).run_method("on_payment_authorized", self.flags.status_changed_to)
except Exception:
frappe.log_error(frappe.get_traceback())
frappe.log_error("Gocardless redirect failed")
if custom_redirect_to:
redirect_to = custom_redirect_to

View File

@@ -152,7 +152,7 @@ def generate_stk_push(**kwargs):
return response
except Exception:
frappe.log_error(title=_("Mpesa Express Transaction Error"))
frappe.log_error("Mpesa Express Transaction Error")
frappe.throw(
_("Issue detected with Mpesa configuration, check the error logs for more details"),
title=_("Mpesa Express Error"),
@@ -203,7 +203,7 @@ def verify_transaction(**kwargs):
integration_request.handle_success(transaction_response)
except Exception:
integration_request.handle_failure(transaction_response)
frappe.log_error(frappe.get_traceback())
frappe.log_error("Mpesa: Failed to verify transaction")
else:
integration_request.handle_failure(transaction_response)
@@ -275,7 +275,7 @@ def get_account_balance(request_payload):
)
return response
except Exception:
frappe.log_error(title=_("Account Balance Processing Error"))
frappe.log_error("Mpesa: Failed to get account balance")
frappe.throw(_("Please check your configuration and try again"), title=_("Error"))
@@ -315,7 +315,7 @@ def process_balance_info(**kwargs):
except Exception:
request.handle_failure(account_balance_response)
frappe.log_error(
title=_("Mpesa Account Balance Processing Error"), message=account_balance_response
title="Mpesa Account Balance Processing Error", message=account_balance_response
)
else:
request.handle_failure(account_balance_response)

View File

@@ -23,7 +23,7 @@ class PlaidConnector:
def get_access_token(self, public_token):
if public_token is None:
frappe.log_error(_("Public token is missing for this bank"), _("Plaid public token error"))
frappe.log_error("Plaid: Public token is missing")
response = self.client.Item.public_token.exchange(public_token)
access_token = response["access_token"]
return access_token
@@ -61,10 +61,10 @@ class PlaidConnector:
try:
response = self.client.LinkToken.create(token_request)
except InvalidRequestError:
frappe.log_error(frappe.get_traceback(), _("Plaid invalid request error"))
frappe.log_error("Plaid: Invalid request error")
frappe.msgprint(_("Please check your Plaid client ID and secret values"))
except APIError as e:
frappe.log_error(frappe.get_traceback(), _("Plaid authentication error"))
frappe.log_error("Plaid: Authentication error")
frappe.throw(_(str(e)), title=_("Authentication Failed"))
else:
return response["link_token"]
@@ -81,7 +81,7 @@ class PlaidConnector:
except requests.Timeout:
pass
except Exception as e:
frappe.log_error(frappe.get_traceback(), _("Plaid authentication error"))
frappe.log_error("Plaid: Authentication error")
frappe.throw(_(str(e)), title=_("Authentication Failed"))
def get_transactions(self, start_date, end_date, account_id=None):
@@ -102,4 +102,4 @@ class PlaidConnector:
except ItemError as e:
raise e
except Exception:
frappe.log_error(frappe.get_traceback(), _("Plaid transactions sync error"))
frappe.log_error("Plaid: Transactions sync error")

View File

@@ -54,7 +54,7 @@ def add_institution(token, response):
)
bank.insert()
except Exception:
frappe.log_error(frappe.get_traceback(), title=_("Plaid Link Error"))
frappe.log_error("Plaid Link Error")
else:
bank = frappe.get_doc("Bank", response["institution"]["name"])
bank.plaid_access_token = access_token
@@ -113,7 +113,7 @@ def add_bank_accounts(response, bank, company):
_("Bank account {0} already exists and could not be created again").format(account["name"])
)
except Exception:
frappe.log_error(frappe.get_traceback(), title=_("Plaid Link Error"))
frappe.log_error("Plaid Link Error")
frappe.throw(
_("There was an error creating Bank Account while linking with Plaid."),
title=_("Plaid Link Failed"),
@@ -135,7 +135,7 @@ def add_bank_accounts(response, bank, company):
existing_account.save()
result.append(existing_bank_account)
except Exception:
frappe.log_error(frappe.get_traceback(), title=_("Plaid Link Error"))
frappe.log_error("Plaid Link Error")
frappe.throw(
_("There was an error updating Bank Account {} while linking with Plaid.").format(
existing_bank_account

View File

@@ -1,6 +1,5 @@
import frappe
import requests
from frappe import _
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_incoming_call
# api/method/erpnext.erpnext_integrations.exotel_integration.handle_end_call
@@ -26,8 +25,7 @@ def handle_incoming_call(**kwargs):
update_call_log(call_payload, call_log=call_log)
except Exception as e:
frappe.db.rollback()
frappe.log_error(title=_("Error in Exotel incoming call"))
frappe.db.commit()
exotel_settings.log_error("Error in Exotel incoming call")
@frappe.whitelist(allow_guest=True)

View File

@@ -22,7 +22,7 @@ def create_stripe_subscription(gateway_controller, data):
return create_subscription_on_stripe(stripe_settings)
except Exception:
frappe.log_error(frappe.get_traceback())
stripe_settings.log_error("Unable to create Stripe subscription")
return {
"redirect_to": frappe.redirect_to_message(
_("Server Error"),
@@ -55,9 +55,9 @@ def create_subscription_on_stripe(stripe_settings):
else:
stripe_settings.integration_request.db_set("status", "Failed", update_modified=False)
frappe.log_error("Subscription N°: " + subscription.id, "Stripe Payment not completed")
frappe.log_error(f"Stripe Subscription ID {subscription.id}: Payment failed")
except Exception:
stripe_settings.integration_request.db_set("status", "Failed", update_modified=False)
frappe.log_error(frappe.get_traceback())
stripe_settings.log_error("Unable to create Stripe subscription")
return stripe_settings.finalize_request()