From fd9b16ece2d778268759e2f156febb20bff008d6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 13 May 2017 17:23:53 +0530 Subject: [PATCH] Better error message for network errors on AJAX queries --- src/pyj/ajax.pyj | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pyj/ajax.pyj b/src/pyj/ajax.pyj index 1b22c1118c..c291253fd7 100644 --- a/src/pyj/ajax.pyj +++ b/src/pyj/ajax.pyj @@ -50,8 +50,10 @@ def ajax(path, on_complete, on_progress=None, bypass_cache=True, method='GET', q xhr.request_path = path xhr.error_html = '' - def set_error(event): - if event is 'timeout': + def set_error(event, is_network_error): + 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) elif event is 'abort': 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) 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': end_type = 'error' if end_type is not 'load': - set_error(end_type) + set_error(end_type, is_network_error) on_complete(end_type, xhr, ev) if on_progress: