21 lines
806 B
TypeScript
21 lines
806 B
TypeScript
import { toast } from 'svelte-sonner';
|
|
|
|
export const notify = {
|
|
success: (message: string, description?: string) =>
|
|
toast.success(message, description ? { description } : undefined),
|
|
error: (message: string, description?: string) =>
|
|
toast.error(message, description ? { description } : undefined),
|
|
info: (message: string, description?: string) =>
|
|
toast.info(message, description ? { description } : undefined),
|
|
warning: (message: string, description?: string) =>
|
|
toast.warning(message, description ? { description } : undefined),
|
|
promise: toast.promise,
|
|
dismiss: toast.dismiss,
|
|
message: toast.message
|
|
};
|
|
|
|
export function notifyApiError(e: unknown, fallback = 'Ошибка запроса') {
|
|
const message = e instanceof Error ? e.message : String(e);
|
|
notify.error(message || fallback);
|
|
}
|