Closes #5383 ## Light theme <img width="905" alt="image" src="https://github.com/twentyhq/twenty/assets/3098428/ab0683c5-ded3-420c-ace6-684d38794a2d"> ## Dark theme <img width="903" alt="image" src="https://github.com/twentyhq/twenty/assets/3098428/4e43ca35-438d-4ba0-8388-1f061c6ccfb0">
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import React, { useCallback, useEffect } from 'react';
|
|
|
|
import { ObjectMetadataItemNotFoundError } from '@/object-metadata/errors/ObjectMetadataNotFoundError';
|
|
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
|
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
|
|
|
export const PromiseRejectionEffect = () => {
|
|
const { enqueueSnackBar } = useSnackBar();
|
|
|
|
const handlePromiseRejection = useCallback(
|
|
(event: PromiseRejectionEvent) => {
|
|
const error = event.reason;
|
|
|
|
// TODO: connect Sentry here
|
|
if (error instanceof ObjectMetadataItemNotFoundError) {
|
|
enqueueSnackBar(
|
|
`Error with custom object that cannot be found : ${event.reason}`,
|
|
{
|
|
variant: SnackBarVariant.Error,
|
|
},
|
|
);
|
|
} else {
|
|
enqueueSnackBar(`Error: ${event.reason}`, {
|
|
variant: SnackBarVariant.Error,
|
|
});
|
|
}
|
|
},
|
|
[enqueueSnackBar],
|
|
);
|
|
|
|
useEffect(() => {
|
|
window.addEventListener('unhandledrejection', handlePromiseRejection);
|
|
|
|
return () => {
|
|
window.removeEventListener('unhandledrejection', handlePromiseRejection);
|
|
};
|
|
}, [handlePromiseRejection]);
|
|
|
|
return <></>;
|
|
};
|