diff --git a/editor.planx.uk/src/lib/graphql.ts b/editor.planx.uk/src/lib/graphql.ts index fde65bbd03..3afcafa1ee 100644 --- a/editor.planx.uk/src/lib/graphql.ts +++ b/editor.planx.uk/src/lib/graphql.ts @@ -4,9 +4,11 @@ import { DefaultContext, from, InMemoryCache, + Operation, } from "@apollo/client"; import { onError } from "@apollo/client/link/error"; import { RetryLink } from "@apollo/client/link/retry"; +import { logger } from "airbrake"; import { toast } from "react-toastify"; import { getCookie } from "./cookie"; @@ -45,14 +47,36 @@ const publicHttpLink = createHttpLink({ headers: { "x-hasura-role": "public" }, }); -const errorLink = onError(({ graphQLErrors }) => { +const handlePermissionErrors = (message: string, operation: Operation) => { + const permissionErrors = [ + // Constraints error - user does not have access to this resource + /permission has failed/gi, + // Query or mutation error - user does not have access to this query + /not found in type/gi, + ]; + + const isPermissionError = permissionErrors.some((re) => re.test(message)); + + if (isPermissionError) { + console.log("CONTEXT: ", operation.getContext()) + logger.notify(`Permission error whilst attempting ${operation.operationName}`) + toast.error("Permission error", { + toastId: "permission_error", + hideProgressBar: true, + progress: undefined, + }); + } +} + +const errorLink = onError(({ graphQLErrors, operation }) => { if (graphQLErrors) { // GraphQL errors are not retried - graphQLErrors.map(({ message, locations, path }) => + graphQLErrors.forEach(({ message, locations, path }) => { console.error( `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`, - ), - ); + ) + handlePermissionErrors(message, operation) + }); } else { toast.error("Network error, attempting to reconnect…", { toastId, diff --git a/editor.planx.uk/src/pages/Team.tsx b/editor.planx.uk/src/pages/Team.tsx index c5fbbe7e47..8fc82b04cc 100644 --- a/editor.planx.uk/src/pages/Team.tsx +++ b/editor.planx.uk/src/pages/Team.tsx @@ -330,7 +330,7 @@ const Team: React.FC = () => { }} /> ))} - {useStore.getState().canUserEditTeam(slug) && ( + {/* {useStore.getState().canUserEditTeam(slug) && ( */} { const newFlowName = prompt("Service name"); @@ -347,7 +347,7 @@ const Team: React.FC = () => { > Add a new service - )} + {/* )} */} )}