fleet/frontend/components/queries/QueryPageWrapper/helpers.js
Martavis Parker 349a88e25b
Forcing 404 page where entity ids do not exist (#3833)
* Allow sort by more than one key

* forcing 404 page where entity ids do not exist

* refactored error boundary; handling 404s now

* added 403 overlay; refactored auth wrappers

* fixed test for maintainer

* more efficient fetches; test fixes

* clarify comment

* clean up

Co-authored-by: Tomas Touceda <[email protected]>
2022-01-27 14:10:12 -08:00

30 lines
967 B
JavaScript

import { push } from "react-router-redux";
import { join, omit, values } from "lodash";
import PATHS from "router/paths";
import queryActions from "redux/nodes/entities/queries/actions";
import { renderFlash } from "redux/nodes/notifications/actions";
export const fetchQuery = (dispatch, queryID) => {
return dispatch(queryActions.load(queryID)).catch((errors) => {
const { MANAGE_QUERIES } = PATHS;
let errorMessage = join(values(omit(errors, "http_status")), ", ");
if (errorMessage.includes("no rows in result set")) {
errorMessage = "The query you requested does not exist in Fleet.";
}
// LEGACY CODE - I had to do this to preserve the Redux pattern :-( MP 1/25/22
if (errorMessage.includes("was not found in the datastore")) {
dispatch(push("/404"));
return;
}
dispatch(push(MANAGE_QUERIES));
dispatch(renderFlash("error", errorMessage));
return false;
});
};
export default { fetchQuery };