The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/admin/import/useErrorHandler.js

34 lines
1000 B

import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch } from '../../contexts/ToastMessagesContext';
import { useTranslation } from '../../contexts/TranslationContext';
export const useErrorHandler = () => {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
return useMutableCallback((error, defaultMessage) => {
console.error(error);
if (typeof error === 'string') {
dispatchToastMessage({ type: 'error', message: error });
return;
}
const errorType = error?.xhr?.responseJSON?.errorType;
if (typeof errorType === 'string' && t.has(errorType)) {
dispatchToastMessage({ type: 'error', message: t(errorType) });
return;
}
if (typeof errorType?.error === 'string' && t.has(errorType.error)) {
dispatchToastMessage({ type: 'error', message: t(errorType?.error) });
return;
}
if (defaultMessage) {
dispatchToastMessage({ type: 'error', message: defaultMessage });
}
});
};