From 5570afeb035045efb74b8f87dd4e7ec9bc753888 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Tue, 26 Jul 2016 14:47:10 +0200 Subject: [PATCH] [WebUI] Friendly error messages for failed learns --- interface/js/rspamd.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/interface/js/rspamd.js b/interface/js/rspamd.js index 1aa96e6fa..be73bf368 100644 --- a/interface/js/rspamd.js +++ b/interface/js/rspamd.js @@ -737,16 +737,14 @@ alertMessage('alert-success', 'Data successfully uploaded'); } }, - // error: function() { - // alertMessage('alert-error', 'Cannot upload data'); - // }, - statusCode: { - 404: function () { - alertMessage('alert-error', 'Cannot upload data, no server found'); - }, - 503: function () { - alertMessage('alert-error', 'Cannot tokenize message, no text data'); + error: function (xhr, textStatus, errorThrown) { + try { + var json = $.parseJSON(xhr.responseText); + var errorMsg = $('').text(json.error).html(); + } catch(err) { + var errorMsg = $('').text("Error: [" + textStatus + "] " + errorThrown).html(); } + alertMessage('alert-error', errorMsg); } }); } -- 2.39.5