From 265f40be18728e61b839be0562a93f6691a2c0b2 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 14 Dec 2018 15:44:59 +0000 Subject: [PATCH] Do not fail miserably if we don't have proper json during error 500 --- src/js/yunohost/helpers.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/js/yunohost/helpers.js b/src/js/yunohost/helpers.js index c7aca7b3..0bbefd85 100644 --- a/src/js/yunohost/helpers.js +++ b/src/js/yunohost/helpers.js @@ -122,9 +122,18 @@ } // 500 else if (xhr.status == 500) { - error_log = JSON.parse(xhr.responseText); - error_log.route = error_log.route.join(' ') + '\n'; - error_log.arguments = JSON.stringify(error_log.arguments); + try { + error_log = JSON.parse(xhr.responseText); + error_log.route = error_log.route.join(' ') + '\n'; + error_log.arguments = JSON.stringify(error_log.arguments); + } + catch (e) + { + error_log = {}; + error_log.route = "Failed to parse route"; + error_log.arguments = "Failed to parse arguments"; + error_log.traceback = xhr.responseText; + } c.flash('fail', y18n.t('internal_exception', [error_log.route, error_log.arguments, error_log.traceback])); } // 502 Bad gateway means API is down