Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Show actual gql errors for Tasks #237

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/AddTask/components/DrushCron.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import ReactSelect from 'react-select';

import Button from 'components/Button';
import gql from 'graphql-tag';
import { bp, color, fontSize } from 'lib/variables';

import { SelectWrapper } from './Styles';

Expand Down
27 changes: 25 additions & 2 deletions src/components/AddTask/components/Error.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
import React from 'react';
import React, { FC, useEffect } from 'react';

const Error = () => <div>Error.</div>;
import { notification } from 'antd';

interface Props {
errMessage: string;
}
const Error: FC<Props> = ({ errMessage }) => {
const [api, contextHolder] = notification.useNotification({ maxCount: 1 });

const showError = (errorMessage: string) => {
api['error']({
message: 'There was a problem running a task.',
description: errorMessage,
placement: 'top',
duration: 0,
style: { width: '500px' },
});
};

useEffect(() => {
if (errMessage) showError(errMessage);
}, [errMessage]);

return <>{contextHolder}</>;
};
export default Error;
4 changes: 3 additions & 1 deletion src/components/AddTask/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const AddTask = ({
setSelectedTask,
onCompleted,
onError,
errMessage,
options,
onNewTask,
}) => {
Expand Down Expand Up @@ -70,7 +71,8 @@ const AddTask = ({
projectEnvironments={projectEnvironments}
selectedTask={selectedTask}
onCompleted={onCompleted}
onError={onError}
onError={e => onError(e.message)}
errMessage={errMessage}
onNewTask={onNewTask}
/>
</div>
Expand Down
9 changes: 6 additions & 3 deletions src/components/AddTask/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import withState from 'recompose/withState';
const { publicRuntimeConfig } = getConfig();

const withSelectedTask = withState('selectedTask', 'setSelectedTask', null);
const withErrMessage = withState('errMessage', 'setErrMessage', null);

const withOptions = withProps(({ pageEnvironment }) => {
let options = [
{
Expand Down Expand Up @@ -78,8 +80,9 @@ const withNewTaskHanders = withHandlers({
setSelectedTask('Completed');
},
onError:
({ setSelectedTask }) =>
() => {
({ setSelectedTask, setErrMessage }) =>
errMsg => {
setErrMessage(errMsg);
setSelectedTask('Error');
},
});
Expand Down Expand Up @@ -117,4 +120,4 @@ const withProjectEnvironments = BaseComponent =>
}
};

export default compose(withSelectedTask, withNewTaskHanders, withOptions, withProjectEnvironments);
export default compose(withSelectedTask, withErrMessage, withNewTaskHanders, withOptions, withProjectEnvironments);
4 changes: 3 additions & 1 deletion src/lib/ApiConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ const ApiConnection = ({ children }) => (
onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`)
console.log(
`[GraphQL error]: Message: ${message}, Location: ${JSON.stringify(locations)}, Path: ${path}`
)
);
if (networkError) console.log('[Network error]', networkError);
}),
Expand Down