Chore: fixes throwing errors on 200 response with influxdb datasource (#24848)

* Chore: fixes throwing errors on 200 response with influxdb datasource

* Chore: changes influxdb error prefix from error to influxdb error
This commit is contained in:
Lukas Siatka 2020-05-25 17:56:16 +02:00 committed by GitHub
parent 1e4e2642bf
commit 7bf5b395b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -322,6 +322,15 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
.datasourceRequest(req)
.then(
(result: any) => {
if (result.data && result.data.results) {
const errors = result.data.results.filter((elem: any) => elem.error);
if (errors.length > 0) {
throw {
message: 'InfluxDB Error: ' + errors[0].error,
data: result.data,
};
}
}
return result.data;
},
(err: any) => {

View File

@ -75,6 +75,46 @@ describe('InfluxDataSource', () => {
});
});
describe('When getting error on 200 after issuing a query', () => {
const queryOptions: any = {
range: {
from: '2018-01-01T00:00:00Z',
to: '2018-01-02T00:00:00Z',
},
rangeRaw: {
from: '2018-01-01T00:00:00Z',
to: '2018-01-02T00:00:00Z',
},
targets: [{}],
timezone: 'UTC',
scopedVars: {
interval: { text: '1m', value: '1m' },
__interval: { text: '1m', value: '1m' },
__interval_ms: { text: 60000, value: 60000 },
},
};
it('throws an error', async () => {
datasourceRequestMock.mockImplementation((req: any) => {
return Promise.resolve({
data: {
results: [
{
error: 'Query timeout',
},
],
},
});
});
try {
await ctx.ds.query(queryOptions);
} catch (err) {
expect(err.message).toBe('InfluxDB Error: Query timeout');
}
});
});
describe('InfluxDataSource in POST query mode', () => {
const ctx: any = {
//@ts-ignore