From 46612a9f68775a50dbd797040796d7871ea80f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 22 Dec 2017 16:25:39 +0100 Subject: [PATCH] JavaScript function for getting reasonable error message from an XHR response --- src/scripts/tutti/5_1_notifications.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/scripts/tutti/5_1_notifications.js b/src/scripts/tutti/5_1_notifications.js index 434aa7d8..2a263d47 100644 --- a/src/scripts/tutti/5_1_notifications.js +++ b/src/scripts/tutti/5_1_notifications.js @@ -361,6 +361,20 @@ function getNotificationsLoop() { }, 30000); } +/* Returns a more-or-less reasonable message given an error response object. */ +function xhrErrorResponseMessage(err) { + if (typeof err.responseJSON == 'undefined') + return err.statusText; + + if (typeof err.responseJSON._error != 'undefined' && typeof err.responseJSON._error.message != 'undefined') + return err.responseJSON._error.message; + + if (typeof err.responseJSON._message != 'undefined') + return err.responseJSON._message + + return err.statusText; +} + /* Notifications: Toastr Defaults */ toastr.options.showDuration = 50; toastr.options.progressBar = true;