refactor: Remove unnecessary exception handling
This commit is contained in:
parent
ff6a2e11d1
commit
af287a04a9
5 changed files with 18 additions and 53 deletions
|
|
@ -266,8 +266,12 @@ class InvalidRemoteException(Exception):
|
|||
|
||||
|
||||
class LinkExpiredError(ValidationError):
|
||||
pass
|
||||
http_status_code = 410
|
||||
title = "Link Expired"
|
||||
message = "The link has been expired"
|
||||
|
||||
|
||||
class InvalidKey(ValidationError):
|
||||
pass
|
||||
http_status_code = 401
|
||||
title = "Invalid Key"
|
||||
message = "The key you are using is invalid"
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
<div class="invalid-state">
|
||||
<img src="/assets/frappe/images/ui-states/empty-app-state.svg"/>
|
||||
<div class="mt-2 text-muted small">
|
||||
{{ _("Key Expired")}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
<div class="invalid-state">
|
||||
<svg width="50" height="50" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" style="margin: auto; --icon-stroke: var(--gray-600)">
|
||||
<path d="M2.5 20.5028L4.7176 18.2852" stroke="var(--icon-stroke)" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M6.06764 10.5684L4.71764 11.9184C3.87361 12.7624 3.39944 13.9071 3.39944 15.1008C3.39944 16.2944 3.87361 17.4391 4.71764 18.2832C5.56166 19.1272 6.70641 19.6014 7.90004 19.6014C9.09367 19.6014 10.2384 19.1272 11.0824 18.2832L12.4324 16.9332L6.06764 10.5684Z" stroke="var(--icon-stroke)" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M20.5 2.5L18.2824 4.7176" stroke="var(--icon-stroke)" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M16.9324 12.4295L18.2824 11.0795C19.1264 10.2355 19.6006 9.09071 19.6006 7.89708C19.6006 6.70345 19.1264 5.5587 18.2824 4.71468C17.4384 3.87065 16.2936 3.39648 15.1 3.39648C13.9064 3.39648 12.7616 3.87065 11.9176 4.71468L10.5676 6.06468L16.9324 12.4295Z" stroke="var(--icon-stroke)" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M9.69999 10.6035L7.89999 12.4035" stroke="var(--icon-stroke)" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M12.4 13.3018L10.6 15.1018" stroke="var(--icon-stroke)" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
||||
<div class="mt-2 text-muted small">
|
||||
{{ _("Key is Invalid")}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -119,18 +119,8 @@ def read_multi_pdf(output):
|
|||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def download_pdf(doctype, name, format=None, doc=None, no_letterhead=0):
|
||||
doc = frappe.get_doc(doctype, name)
|
||||
doc.doctype = doctype
|
||||
try:
|
||||
validate_print_permission(doc)
|
||||
except frappe.exceptions.LinkExpiredError:
|
||||
frappe.local.response.http_status_code = 410
|
||||
frappe.local.response.message = _("Link Expired")
|
||||
return
|
||||
except frappe.exceptions.InvalidKey:
|
||||
frappe.local.response.http_status_code = 401
|
||||
frappe.local.response.message = _("Invalid Key")
|
||||
return
|
||||
doc = doc or frappe.get_doc(doctype, name)
|
||||
validate_print_permission(doc)
|
||||
|
||||
html = frappe.get_print(doctype, name, format, doc=doc, no_letterhead=no_letterhead)
|
||||
frappe.local.response.filename = "{name}.pdf".format(
|
||||
|
|
|
|||
|
|
@ -48,25 +48,16 @@ def get_context(context):
|
|||
|
||||
is_invalid_print = False
|
||||
print_style = None
|
||||
try:
|
||||
body = get_rendered_template(
|
||||
doc,
|
||||
print_format=print_format,
|
||||
meta=meta,
|
||||
trigger_print=frappe.form_dict.trigger_print,
|
||||
no_letterhead=frappe.form_dict.no_letterhead,
|
||||
letterhead=letterhead,
|
||||
settings=settings,
|
||||
)
|
||||
print_style = get_print_style(frappe.form_dict.style, print_format)
|
||||
except frappe.exceptions.LinkExpiredError:
|
||||
body = frappe.get_template("templates/print_format/print_key_expired.html").render({})
|
||||
context.http_status_code = 410
|
||||
is_invalid_print = True
|
||||
except frappe.exceptions.InvalidKey:
|
||||
body = frappe.get_template("templates/print_format/print_key_invalid.html").render({})
|
||||
context.http_status_code = 401
|
||||
is_invalid_print = True
|
||||
body = get_rendered_template(
|
||||
doc,
|
||||
print_format=print_format,
|
||||
meta=meta,
|
||||
trigger_print=frappe.form_dict.trigger_print,
|
||||
no_letterhead=frappe.form_dict.no_letterhead,
|
||||
letterhead=letterhead,
|
||||
settings=settings,
|
||||
)
|
||||
print_style = get_print_style(frappe.form_dict.style, print_format)
|
||||
|
||||
return {
|
||||
"body": body,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue