summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/srp/src/jqueryRest.js
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2017-03-23 16:35:42 +0100
committerAzul <azul@riseup.net>2017-03-23 16:35:42 +0100
commitc11e31acf3a592b8560459469ae4acf0e6e5dfd4 (patch)
tree9130225ec9af905aaad9ed7f8fa64dbc22d574da /app/assets/javascripts/srp/src/jqueryRest.js
parent94ba8eae189ef6d60ddfa194e73b672123e17d6f (diff)
fix: display error js responses in dev environment
Sometimes the dev environment will send back a plain text response. This causes the json parser to raise an exception and used to cause the browser not to display any error message. Now we dumpt the whole server response - which happes to also include the backtrace. A lot more useful than doing nothing. In production this should never happen as 500s get handled by the ExceptionApplication / our ErrorsController there.
Diffstat (limited to 'app/assets/javascripts/srp/src/jqueryRest.js')
-rw-r--r--app/assets/javascripts/srp/src/jqueryRest.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/app/assets/javascripts/srp/src/jqueryRest.js b/app/assets/javascripts/srp/src/jqueryRest.js
index 0c58eb2..437bd65 100644
--- a/app/assets/javascripts/srp/src/jqueryRest.js
+++ b/app/assets/javascripts/srp/src/jqueryRest.js
@@ -88,10 +88,17 @@ srp.remote = (function(){
// the http error response.
function error(xhr, text, thrown)
{
- if (xhr.responseText && xhr.responseText != "")
- srp.error($.parseJSON(xhr.responseText));
- else
- srp.error("Server did not respond.");
+ var message;
+ if (xhr.responseText && xhr.responseText != "") {
+ try {
+ message = $.parseJSON(xhr.responseText);
+ } catch (err) {
+ message = xhr.responseText;
+ }
+ } else {
+ message = "Server did not respond.";
+ }
+ srp.error(message);
};
return {