processQueryErrorsEpic.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Epic } from 'redux-observable';
  2. import { mergeMap } from 'rxjs/operators';
  3. import { NEVER, of } from 'rxjs';
  4. import { ActionOf } from 'app/core/redux/actionCreatorFactory';
  5. import { StoreState } from 'app/types/store';
  6. import { instanceOfDataQueryError } from 'app/core/utils/explore';
  7. import { toDataQueryError } from 'app/features/dashboard/state/PanelQueryState';
  8. import { processQueryErrorsAction, ProcessQueryErrorsPayload, queryFailureAction } from '../actionTypes';
  9. export const processQueryErrorsEpic: Epic<ActionOf<any>, ActionOf<any>, StoreState> = (action$, state$) => {
  10. return action$.ofType(processQueryErrorsAction.type).pipe(
  11. mergeMap((action: ActionOf<ProcessQueryErrorsPayload>) => {
  12. const { exploreId, datasourceId } = action.payload;
  13. let { response } = action.payload;
  14. const { datasourceInstance, eventBridge } = state$.value.explore[exploreId];
  15. if (datasourceInstance.meta.id !== datasourceId || response.cancelled) {
  16. // Navigated away, queries did not matter
  17. return NEVER;
  18. }
  19. // For Angular editors
  20. eventBridge.emit('data-error', response);
  21. console.error(response); // To help finding problems with query syntax
  22. if (!instanceOfDataQueryError(response)) {
  23. response = toDataQueryError(response);
  24. }
  25. return of(
  26. queryFailureAction({
  27. exploreId,
  28. response,
  29. })
  30. );
  31. })
  32. );
  33. };