Commit 7bf5b395 by Lukas Siatka Committed by GitHub

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
parent 1e4e2642
......@@ -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) => {
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment