mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Better error message for network errors on AJAX queries
This commit is contained in:
parent
900841e13a
commit
fd9b16ece2
@ -50,8 +50,10 @@ def ajax(path, on_complete, on_progress=None, bypass_cache=True, method='GET', q
|
|||||||
xhr.request_path = path
|
xhr.request_path = path
|
||||||
xhr.error_html = ''
|
xhr.error_html = ''
|
||||||
|
|
||||||
def set_error(event):
|
def set_error(event, is_network_error):
|
||||||
if event is 'timeout':
|
if is_network_error:
|
||||||
|
xhr.error_html = str.format(_('Failed to communicate with "{}", network error, is the server running and accessible?'), xhr.request_path)
|
||||||
|
elif event is 'timeout':
|
||||||
xhr.error_html = str.format(_('Failed to communicate with "{}", timed out after: {} seconds'), xhr.request_path, timeout/1000)
|
xhr.error_html = str.format(_('Failed to communicate with "{}", timed out after: {} seconds'), xhr.request_path, timeout/1000)
|
||||||
elif event is 'abort':
|
elif event is 'abort':
|
||||||
xhr.error_html = str.format(_('Failed to communicate with "{}", aborted'), xhr.request_path)
|
xhr.error_html = str.format(_('Failed to communicate with "{}", aborted'), xhr.request_path)
|
||||||
@ -75,10 +77,11 @@ def ajax(path, on_complete, on_progress=None, bypass_cache=True, method='GET', q
|
|||||||
on_progress(ev.loaded, ul, xhr)
|
on_progress(ev.loaded, ul, xhr)
|
||||||
|
|
||||||
def complete_callback(end_type, ev):
|
def complete_callback(end_type, ev):
|
||||||
|
is_network_error = ev if end_type is 'error' else False
|
||||||
if xhr.status is not ok_code and end_type is 'load':
|
if xhr.status is not ok_code and end_type is 'load':
|
||||||
end_type = 'error'
|
end_type = 'error'
|
||||||
if end_type is not 'load':
|
if end_type is not 'load':
|
||||||
set_error(end_type)
|
set_error(end_type, is_network_error)
|
||||||
on_complete(end_type, xhr, ev)
|
on_complete(end_type, xhr, ev)
|
||||||
|
|
||||||
if on_progress:
|
if on_progress:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user