mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-27 22:54:07 +00:00
* Move dmg-license to optionalDependencies so it can be installed on windows * Extend toastError to accept a default error message * Throw BrunoError when in deleteWorkspace * Handle errors with the toastError * Use existing parseError for getting errorMsg in toastError
37 lines
842 B
JavaScript
37 lines
842 B
JavaScript
import toast from 'react-hot-toast';
|
|
|
|
// levels: 'warning, error'
|
|
export class BrunoError extends Error {
|
|
constructor(message, level) {
|
|
super(message);
|
|
this.name = 'BrunoError';
|
|
this.level = level || 'error';
|
|
}
|
|
}
|
|
|
|
export const parseError = (error, defaultErrorMsg = 'An error occurred') => {
|
|
if (error instanceof BrunoError) {
|
|
return error.message;
|
|
}
|
|
|
|
return error.message ? error.message : defaultErrorMsg;
|
|
};
|
|
|
|
export const toastError = (error, defaultErrorMsg = 'An error occurred') => {
|
|
let errorMsg = parseError(error, defaultErrorMsg);
|
|
|
|
if (error instanceof BrunoError) {
|
|
if (error.level === 'warning') {
|
|
return toast(errorMsg, {
|
|
icon: '⚠️',
|
|
duration: 3000
|
|
});
|
|
}
|
|
return toast.error(errorMsg, {
|
|
duration: 3000
|
|
});
|
|
}
|
|
|
|
return toast.error(errorMsg);
|
|
};
|