import { Alert, AlertTitle } from '@mui/material'; import { HttpError } from '../client/HttpError'; import { useDialogContext } from './dialogContext'; import { NewTabLink } from './Link'; type Props = { error: HttpError | Error; severity?: 'error' | 'info'; }; export const ErrorAlert = ({ error, severity = 'error' }: Props) => { const apiUrl = useDialogContext((c) => c.uiProps.apiUrl); return ( {error instanceof HttpError ? getErrorContent(error, apiUrl) : error.message} ); }; function DocsInContext() { return ( Learn more in Docs ); } function DocsAPIKeys() { return ( Learn more in Docs ); } function getErrorContent({ code, params, message }: HttpError, apiUrl: string) { switch (code) { case 'operation_not_permitted': return ( <> Operation not permitted {Boolean(params?.length) && 'Missing scopes: ' + params?.join(', ')} ); case 'invalid_project_api_key': return ( <> Invalid API key Check it in the code or in the chrome plugin. ); case 'api_url_not_specified': return ( <> Oops... I miss the API url Add it in the code or via the chrome plugin. ); case 'api_url_not_valid': return ( <> API url is not correct ({apiUrl}) Check it in the code or in the chrome plugin. ); case 'api_key_not_specified': return ( <> Oops... I miss the API key Add it in the code or via the chrome plugin. ); case 'permissions_not_sufficient_to_edit': return ( <> Sorry, you don't have permissions to make changes Update your API key or ask admin for more permissions ); case 'fetch_error': return `Failed to fetch (${apiUrl})`; default: return message; } }