mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-29 07:34:07 +00:00
feat: local collections displayed separately (resolves #22)
This commit is contained in:
34
packages/bruno-app/src/utils/common/error.js
Normal file
34
packages/bruno-app/src/utils/common/error.js
Normal file
@@ -0,0 +1,34 @@
|
||||
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) => {
|
||||
if(error instanceof BrunoError) {
|
||||
return error.message;
|
||||
}
|
||||
|
||||
return error.message ? error.message : 'An error occured';
|
||||
};
|
||||
|
||||
export const toastError = (error) => {
|
||||
if(error instanceof BrunoError) {
|
||||
if(error.level === 'warning') {
|
||||
return toast(error.message, {
|
||||
icon: '⚠️',
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
return toast.error(error.message, {
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
|
||||
return toast.error(error.message || 'An error occured');
|
||||
};
|
||||
Reference in New Issue
Block a user