diff --git a/public/app/plugins/datasource/stackdriver/datasource.ts b/public/app/plugins/datasource/stackdriver/datasource.ts index d73704abb8e..2d47493ffc9 100644 --- a/public/app/plugins/datasource/stackdriver/datasource.ts +++ b/public/app/plugins/datasource/stackdriver/datasource.ts @@ -198,13 +198,13 @@ export default class StackdriverDatasource { title: 'Success', }; } catch (error) { - console.log(error.data.error); let message = 'Stackdriver: '; message += error.statusText ? error.statusText + ': ' : ''; - - if (error.data && error.data.error && error.data.error) { + if (error.data && error.data.error) { try { + console.log(error.data.error); const res = JSON.parse(error.data.error); + console.log(res); message += res.error.code + '. ' + res.error.message; } catch (err) { message += error.data.error; diff --git a/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts b/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts index ab0c0653816..8707270477f 100644 --- a/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts +++ b/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts @@ -53,7 +53,9 @@ describe('StackdriverDataSource', () => { datasourceRequest: async () => Promise.reject({ statusText: 'Bad Request', - data: { error: { code: 400, message: 'Field interval.endTime had an invalid value' } }, + data: { + error: JSON.stringify({ error: { code: 400, message: 'Field interval.endTime had an invalid value' } }), + }, }), }; ds = new StackdriverDataSource(instanceSettings, backendSrv, templateSrv, timeSrv); @@ -67,43 +69,6 @@ describe('StackdriverDataSource', () => { }); }); - describe('when performing getProjects', () => { - describe('and call to resource manager api succeeds', () => { - let ds; - let result; - beforeEach(async () => { - const response = { - projects: [ - { - projectNumber: '853996325002', - projectId: 'test-project', - lifecycleState: 'ACTIVE', - name: 'Test Project', - createTime: '2015-06-02T14:16:08.520Z', - parent: { - type: 'organization', - id: '853996325002', - }, - }, - ], - }; - const backendSrv = { - async datasourceRequest() { - return Promise.resolve({ status: 200, data: response }); - }, - }; - ds = new StackdriverDataSource(instanceSettings, backendSrv, templateSrv, timeSrv); - result = await ds.getProjects(); - }); - - it('should return successfully', () => { - expect(result.length).toBe(1); - expect(result[0].id).toBe('test-project'); - expect(result[0].name).toBe('Test Project'); - }); - }); - }); - describe('When performing query', () => { const options = { range: {