Skip to content

Commit

Permalink
Fix: Show actual gql errors for Tasks (#237)
Browse files Browse the repository at this point in the history
* show gql error messages

* show error notification instead
  • Loading branch information
DaveDarsa authored May 15, 2024
1 parent 027fbbf commit 7d20f3a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
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

0 comments on commit 7d20f3a

Please sign in to comment.