fix: Show toast on clipboard errors

This commit is contained in:
Fayaz Ahmed
2024-06-11 07:12:42 +05:30
parent 20b2dc8c6f
commit fe8e58a80b
@@ -5,10 +5,17 @@
* @param {string} text text to be written to the clipboard
* @throws {Error} unable to copy text to clipboard
*/
import { emitter } from 'shared/helpers/mitt';
export const copyTextToClipboard = async text => {
try {
await navigator.clipboard.writeText(text);
} catch (error) {
// TODO: show localized error message
emitter.emit(
'newToastMessage',
'Network Error: Unable to copy text to clipboard.'
);
throw new Error(`Unable to copy text to clipboard: ${error.message}`);
}
};