mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
1e4e2642bf
commit
7bf5b395b6
@ -322,6 +322,15 @@ export default class InfluxDatasource extends DataSourceApi<InfluxQuery, InfluxO
|
|||||||
.datasourceRequest(req)
|
.datasourceRequest(req)
|
||||||
.then(
|
.then(
|
||||||
(result: any) => {
|
(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;
|
return result.data;
|
||||||
},
|
},
|
||||||
(err: any) => {
|
(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', () => {
|
describe('InfluxDataSource in POST query mode', () => {
|
||||||
const ctx: any = {
|
const ctx: any = {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
Loading…
Reference in New Issue
Block a user