Skip to content

Commit

Permalink
refactor: update useSnackbar composable
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenyWas committed Jul 26, 2024
1 parent c2a3425 commit 8c1a9f2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions composables/useSnackbar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isError, isString } from 'lodash-es';
import { get, isError, isString } from 'lodash-es';
import { VSnackbar } from 'vuetify/lib/components/index.mjs';

interface Snackbar
Expand Down Expand Up @@ -27,18 +27,21 @@ interface SnackbarState {
isActive: boolean;
}

// @ts-expect-error
const getMessage = (value: unknown) => value?.statusMessage || value?.message;

const createSnackbar = (value: unknown, options = {} as SnackbarOptions): Snackbar => {
switch (true) {
case isString(value):
return { text: value, ...options };
// @ts-expect-error
case isNuxtError(value):
return { text: value.statusMessage || value.message };
return { text: getMessage(value) };
case isError(value):
return { text: value.message, ...options };
return { text: getMessage(value), ...options };
default:
try {
return { text: JSON.stringify(value), ...options };
return { text: get(value, 'statusMessage') || JSON.stringify(value), ...options };
} catch (error) {
return options;
}
Expand Down

0 comments on commit 8c1a9f2

Please sign in to comment.