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

Commit b39ce70

Browse files
author
Ivan Filho
committed
Merge pull request #273 from GoogleCloudPlatform/dev-joemu-fix-unexpectederror
Fixes silent failure issues
2 parents 72ec6e5 + 65da8fd commit b39ce70

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

client/components/widget/data_viz/gviz/gviz-directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ explorer.components.widget.data_viz.gviz.gvizChart = function(
141141
message = gvizChart.ERR_SAFE_MODE;
142142
}
143143
else if (scope.widgetConfig.queryError) {
144-
message = 'query error: ' + scope.widgetConfig.queryError;
144+
message = scope.widgetConfig.queryError;
145145
}
146146
else if (scope.widgetConfig.state().datasource.status ===
147147
ResultsDataStatus.NODATA) {

client/components/widget/query/query-result-data-service.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ const WorkQueueService = explorer.components.util.WorkQueueService;
4444
const WidgetConfig = explorer.models.WidgetConfig;
4545

4646

47+
const ERR_FETCH = ''
48+
const ERR_UNEXPECTED = 'The HTTP response returned no details.';
49+
4750
/**
4851
* See module docstring for more information about purpose and usage.
4952
*
@@ -226,7 +229,14 @@ QueryResultDataService.prototype.fetchResults = function(widget) {
226229
isSelected);
227230

228231
promise.then(angular.bind(this, function(response) {
229-
if (response.data.error) {
232+
if (goog.isDefAndNotNull(response.data.error)) {
233+
if (goog.string.isEmptySafe(response.data.error)) {
234+
response.data.error = ERR_UNEXPECTED;
235+
}
236+
response.data.error = (
237+
'An error occurred when fetching data from ' + widget.model.datasource.type + ': ' +
238+
response.data.error
239+
);
230240
this.errorService_.addError(ErrorTypes.DANGER, response.data.error);
231241
deferred.reject(response.data);
232242
} else {
@@ -269,7 +279,11 @@ QueryResultDataService.prototype.fetchResults = function(widget) {
269279
}));
270280
// Error handling
271281
promise.then(null, angular.bind(this, function(response) {
272-
this.errorService_.addError(ErrorTypes.DANGER, response.error || response.statusText);
282+
response.error = (
283+
'An error occurred when fetching data from ' + widget.model.datasource.type + ': ' +
284+
(response.error || response.statusText)
285+
);
286+
this.errorService_.addError(ErrorTypes.DANGER, response.error);
273287

274288
deferred.reject(response);
275289
}));

client/components/widget/query/query-result-data-service_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,36 @@ describe('queryResultDataService', function() {
119119

120120
describe('fetchResults', function() {
121121

122+
it('should apply a default error messsage when an empty error is returned',
123+
function() {
124+
var response = null;
125+
var query = endpoint;
126+
var widget = new ChartWidgetConfig(widgetFactorySvc);
127+
widget.model.datasource.query = 'fakeQuery1';
128+
129+
var mockResponse = {
130+
endpoint: '/data/sql',
131+
error: ''
132+
}
133+
134+
var params = {
135+
'dashboard_id': null,
136+
'id': widget.model.id,
137+
'datasource': widget.model.datasource
138+
};
139+
httpBackend.expectPOST(query, params).respond(mockResponse);
140+
141+
var promise = svc.fetchResults(widget);
142+
promise.catch(function(data) {
143+
response = data;
144+
});
145+
146+
httpBackend.flush();
147+
expect(response).not.toBeNull();
148+
expect(response.error).toBe('An unexpected error occurred.');
149+
}
150+
);
151+
122152
it('should fetch the samples results of a query as a DataTable.',
123153
function() {
124154
var dataTable = null;

0 commit comments

Comments
 (0)