Skip to content

Commit

Permalink
Improve the error message in the slices (#555)
Browse files Browse the repository at this point in the history
* Improve the error message in the slices

Let slice.error() accept msg and xhr

* Check error first in nvd3_vis.js
  • Loading branch information
x4base authored and mistercrunch committed Jun 21, 2016
1 parent 7e8053a commit 40e1787
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 27 deletions.
22 changes: 20 additions & 2 deletions caravel/assets/javascripts/modules/caravel.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,27 @@ var px = (function () {
$('.query-and-save button').removeAttr('disabled');
always(data);
},
error: function (msg) {
getErrorMsg: function (xhr) {
if (xhr.statusText === "timeout") {
return "The request timed out";
}
var msg = "";
if (!xhr.responseText) {
var status = xhr.status;
msg += "An unknown error occurred. (Status: " + status + ")";
if (status === 0) {
// This may happen when the worker in gunicorn times out
msg += " Maybe the request timed out?";
}
}
return msg;
},
error: function (msg, xhr) {
token.find("img.loading").hide();
var err = '<div class="alert alert-danger">' + msg + '</div>';
var err = msg ? ('<div class="alert alert-danger">' + msg + '</div>') : "";
if (xhr) {
err += '<div class="alert alert-danger">' + this.getErrorMsg(xhr) + '</div>';
}
container.html(err);
container.show();
$('span.query').removeClass('disabled');
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/big_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function bigNumberVis(slice) {
d3.json(slice.jsonEndpoint(), function (error, payload) {
//Define the percentage bounds that define color from red to green
if (error !== null) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}
div.html(''); //reset
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/cal_heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function calHeatmap(slice) {
d3.json(slice.jsonEndpoint(), function (error, json) {

if (error !== null) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/directed_force.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function directedForceVis(slice) {
var charge = json.form_data.charge || -500;

if (error !== null) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}
var links = json.data;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/filter_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function filterBox(slice) {
}
})
.fail(function (xhr) {
slice.error(xhr.responseText);
slice.error(xhr.responseText, xhr);
});
};
return {
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function heatmapVis(slice) {
slice.container.html('');
var matrix = {};
if (error) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}
var fd = payload.form_data;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/horizon.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function horizonViz(slice) {
d3.json(slice.jsonEndpoint(), function (error, payload) {
var fd = payload.form_data;
if (error) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function iframeWidget(slice) {
slice.done(payload);
})
.fail(function (xhr) {
slice.error(xhr.responseText);
slice.error(xhr.responseText, xhr);
});
}

Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function markupWidget(slice) {
slice.done(payload);
})
.fail(function (xhr) {
slice.error(xhr.responseText);
slice.error(xhr.responseText, xhr);
});
}

Expand Down
16 changes: 7 additions & 9 deletions caravel/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ function nvd3Vis(slice) {

var render = function () {
d3.json(slice.jsonEndpoint(), function (error, payload) {
slice.container.html('');
// Check error first, otherwise payload can be null
if (error) {
slice.error(error.responseText, error);
return '';
}

var width = slice.width();
var fd = payload.form_data;
var barchartWidth = function () {
Expand All @@ -30,15 +37,6 @@ function nvd3Vis(slice) {
return width;
}
};
slice.container.html('');
if (error) {
if (error.responseText) {
slice.error(error.responseText);
} else {
slice.error(error);
}
return '';
}
var viz_type = fd.viz_type;
var f = d3.format('.3s');
var reduceXTicks = fd.reduce_x_ticks || false;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/parallel_coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function parallelCoordVis(slice) {
slice.done(payload);
})
.fail(function (xhr) {
slice.error(xhr.responseText);
slice.error(xhr.responseText, xhr);
});
}

Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/pivot_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function (slice) {
}
slice.done(json);
}).fail(function (xhr) {
slice.error(xhr.responseText);
slice.error(xhr.responseText, xhr);
});
}
return {
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/sankey.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function sankeyVis(slice) {

d3.json(slice.jsonEndpoint(), function (error, json) {
if (error !== null) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}
var links = json.data;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/sunburst.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function sunburstVis(slice) {

d3.json(slice.jsonEndpoint(), function (error, rawData) {
if (error !== null) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}
createBreadcrumbs(rawData);
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function tableVis(slice) {
$.getJSON(slice.jsonEndpoint(), onSuccess).fail(onError);

function onError(xhr) {
slice.error(xhr.responseText);
slice.error(xhr.responseText, xhr);
}

function onSuccess(json) {
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/treemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function treemap(slice) {
d3.json(slice.jsonEndpoint(), function (error, json) {

if (error !== null) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/word_cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function wordCloudChart(slice) {
function refresh() {
d3.json(slice.jsonEndpoint(), function (error, json) {
if (error !== null) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}
var data = json.data;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/world_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function worldMapChart(slice) {
var fd = json.form_data;

if (error !== null) {
slice.error(error.responseText);
slice.error(error.responseText, error);
return '';
}
var ext = d3.extent(json.data, function (d) {
Expand Down

0 comments on commit 40e1787

Please sign in to comment.