mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugin query API: Handle multiple errors (#63553)
This commit is contained in:
committed by
GitHub
parent
b211ec0a1d
commit
c84cfd2b3f
@@ -451,9 +451,15 @@ export interface DataQueryResponse {
|
||||
|
||||
/**
|
||||
* Optionally include error info along with the response data
|
||||
* @deprecated use errors instead -- will be removed in Grafana 10+
|
||||
*/
|
||||
error?: DataQueryError;
|
||||
|
||||
/**
|
||||
* Optionally include multiple errors for different targets
|
||||
*/
|
||||
errors?: DataQueryError[];
|
||||
|
||||
/**
|
||||
* Use this to control which state the response should have
|
||||
* Defaults to LoadingState.Done if state is not defined
|
||||
|
||||
@@ -57,6 +57,11 @@ export interface PanelData {
|
||||
timings?: DataQueryTimings;
|
||||
|
||||
/** Any query errors */
|
||||
errors?: DataQueryError[];
|
||||
/**
|
||||
* Single error for legacy reasons
|
||||
* @deprecated use errors instead -- will be removed in Grafana 10+
|
||||
*/
|
||||
error?: DataQueryError;
|
||||
|
||||
/** Contains the range from the request or a shifted time range if a request uses relative time */
|
||||
|
||||
@@ -356,6 +356,12 @@ describe('Query Response parser', () => {
|
||||
"refId": "A",
|
||||
}
|
||||
`);
|
||||
expect(res.errors).toEqual([
|
||||
{
|
||||
message: 'Hello Error',
|
||||
refId: 'A',
|
||||
},
|
||||
]);
|
||||
|
||||
const norm = res.data.map((f) => toDataFrameDTO(f));
|
||||
expect(norm).toMatchInlineSnapshot(`
|
||||
|
||||
@@ -87,8 +87,13 @@ export function toDataQueryResponse(
|
||||
refId: dr.refId,
|
||||
message: dr.error,
|
||||
};
|
||||
rsp.state = LoadingState.Error;
|
||||
}
|
||||
if (rsp.errors) {
|
||||
rsp.errors.push({ refId: dr.refId, message: dr.error });
|
||||
} else {
|
||||
rsp.errors = [{ refId: dr.refId, message: dr.error }];
|
||||
}
|
||||
rsp.state = LoadingState.Error;
|
||||
}
|
||||
|
||||
if (dr.frames?.length) {
|
||||
|
||||
Reference in New Issue
Block a user