diff --git a/packages/web/lib/networking/mutations/setIntegrationMutation.ts b/packages/web/lib/networking/mutations/setIntegrationMutation.ts index 78db04487..4493c68ac 100644 --- a/packages/web/lib/networking/mutations/setIntegrationMutation.ts +++ b/packages/web/lib/networking/mutations/setIntegrationMutation.ts @@ -23,9 +23,17 @@ type SetIntegrationResult = { setIntegration: SetIntegrationData } +export enum SetIntegrationErrorCode { + AlreadyExists = 'ALREADY_EXISTS', + BadRequest = 'BAD_REQUEST', + InvalidToken = 'INVALID_TOKEN', + NotFound = 'NOT_FOUND', + Unauthorized = 'UNAUTHORIZED', +} + type SetIntegrationData = { integration: Integration - errorCodes?: string[] + errorCodes?: SetIntegrationErrorCode[] } type Integration = { @@ -66,8 +74,8 @@ export async function setIntegrationMutation( const data = (await gqlFetcher(mutation, { input })) as SetIntegrationResult const error = data.setIntegration.errorCodes?.find(() => true) if (error) { - if (error === 'INVALID_TOKEN') throw 'Your token is invalid.' - throw error + throw new Error(error) } + return data.setIntegration.integration } diff --git a/packages/web/pages/settings/integrations/notion.tsx b/packages/web/pages/settings/integrations/notion.tsx index db15ec21c..f6626cd76 100644 --- a/packages/web/pages/settings/integrations/notion.tsx +++ b/packages/web/pages/settings/integrations/notion.tsx @@ -13,7 +13,10 @@ import { Task, TaskState, } from '../../../lib/networking/mutations/exportToIntegrationMutation' -import { setIntegrationMutation } from '../../../lib/networking/mutations/setIntegrationMutation' +import { + SetIntegrationErrorCode, + setIntegrationMutation, +} from '../../../lib/networking/mutations/setIntegrationMutation' import { apiFetcher } from '../../../lib/networking/networkHelpers' import { useGetIntegrationQuery } from '../../../lib/networking/queries/useGetIntegrationQuery' import { showSuccessToast } from '../../../lib/toastHelpers' @@ -86,6 +89,13 @@ export default function Notion(): JSX.Element { revalidate() messageApi.success('Notion settings updated successfully.') } catch (error) { + if ( + error instanceof Error && + error.message === SetIntegrationErrorCode.NotFound + ) { + return messageApi.error('Notion database not found. Please make sure if you are using database ID instead of page ID.') + } + messageApi.error('There was an error updating Notion settings.') } }