Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #273 from GoogleCloudPlatform/dev-joemu-fix-unexpe…
Browse files Browse the repository at this point in the history
…ctederror

Fixes silent failure issues
  • Loading branch information
Ivan Filho committed Mar 29, 2016
2 parents 72ec6e5 + 65da8fd commit b39ce70
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/components/widget/data_viz/gviz/gviz-directive.js
Expand Up @@ -141,7 +141,7 @@ explorer.components.widget.data_viz.gviz.gvizChart = function(
message = gvizChart.ERR_SAFE_MODE;
}
else if (scope.widgetConfig.queryError) {
message = 'query error: ' + scope.widgetConfig.queryError;
message = scope.widgetConfig.queryError;
}
else if (scope.widgetConfig.state().datasource.status ===
ResultsDataStatus.NODATA) {
Expand Down
18 changes: 16 additions & 2 deletions client/components/widget/query/query-result-data-service.js
Expand Up @@ -44,6 +44,9 @@ const WorkQueueService = explorer.components.util.WorkQueueService;
const WidgetConfig = explorer.models.WidgetConfig;


const ERR_FETCH = ''
const ERR_UNEXPECTED = 'The HTTP response returned no details.';

/**
* See module docstring for more information about purpose and usage.
*
Expand Down Expand Up @@ -226,7 +229,14 @@ QueryResultDataService.prototype.fetchResults = function(widget) {
isSelected);

promise.then(angular.bind(this, function(response) {
if (response.data.error) {
if (goog.isDefAndNotNull(response.data.error)) {
if (goog.string.isEmptySafe(response.data.error)) {
response.data.error = ERR_UNEXPECTED;
}
response.data.error = (
'An error occurred when fetching data from ' + widget.model.datasource.type + ': ' +
response.data.error
);
this.errorService_.addError(ErrorTypes.DANGER, response.data.error);
deferred.reject(response.data);
} else {
Expand Down Expand Up @@ -269,7 +279,11 @@ QueryResultDataService.prototype.fetchResults = function(widget) {
}));
// Error handling
promise.then(null, angular.bind(this, function(response) {
this.errorService_.addError(ErrorTypes.DANGER, response.error || response.statusText);
response.error = (
'An error occurred when fetching data from ' + widget.model.datasource.type + ': ' +
(response.error || response.statusText)
);
this.errorService_.addError(ErrorTypes.DANGER, response.error);

deferred.reject(response);
}));
Expand Down
30 changes: 30 additions & 0 deletions client/components/widget/query/query-result-data-service_test.js
Expand Up @@ -119,6 +119,36 @@ describe('queryResultDataService', function() {

describe('fetchResults', function() {

it('should apply a default error messsage when an empty error is returned',
function() {
var response = null;
var query = endpoint;
var widget = new ChartWidgetConfig(widgetFactorySvc);
widget.model.datasource.query = 'fakeQuery1';

var mockResponse = {
endpoint: '/data/sql',
error: ''
}

var params = {
'dashboard_id': null,
'id': widget.model.id,
'datasource': widget.model.datasource
};
httpBackend.expectPOST(query, params).respond(mockResponse);

var promise = svc.fetchResults(widget);
promise.catch(function(data) {
response = data;
});

httpBackend.flush();
expect(response).not.toBeNull();
expect(response.error).toBe('An unexpected error occurred.');
}
);

it('should fetch the samples results of a query as a DataTable.',
function() {
var dataTable = null;
Expand Down

0 comments on commit b39ce70

Please sign in to comment.