diff --git a/package.json b/package.json index e5d6f00d..7753caf1 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@emotion/cache": "11.10.8", "@emotion/react": "11.11.1", "@emotion/styled": "11.11.0", - "@graasp/query-client": "1.4.0", + "@graasp/query-client": "1.4.1", "@graasp/sdk": "1.2.0", "@graasp/translations": "1.18.0", "@graasp/ui": "3.3.0", @@ -41,6 +41,7 @@ "build": "vite build", "build:dev": "vite build --mode development", "preview": "vite preview", + "preview:dev": "vite preview --mode development", "lint": "eslint .", "pre-commit": "yarn prettier:check && yarn lint", "prettier:check": "prettier --check {src,cypress}/**/*.{js,ts,tsx}", diff --git a/src/config/notifier.ts b/src/config/notifier.ts index 0d546178..e7cf40ef 100644 --- a/src/config/notifier.ts +++ b/src/config/notifier.ts @@ -1,6 +1,8 @@ +import { AxiosError } from 'axios'; import { toast } from 'react-toastify'; -import { routines } from '@graasp/query-client'; +import { Notifier, routines } from '@graasp/query-client'; +import { FAILURE_MESSAGES } from '@graasp/translations'; import { SHOW_NOTIFICATIONS } from './env'; import i18n from './i18n'; @@ -12,13 +14,18 @@ const { signInWithPasswordRoutine, } = routines; -const notifier = (args: { - type: string; - payload?: { - error?: Error; - message?: string; - }; -}) => { +const getErrorMessage = ( + error: Parameters[0]['payload']['error'], +) => { + if (error instanceof AxiosError) { + if (error.isAxiosError) { + return error.response.data.message ?? FAILURE_MESSAGES.UNEXPECTED_ERROR; + } + } + return FAILURE_MESSAGES.UNEXPECTED_ERROR; +}; + +const notifier: Notifier = (args) => { const { type, payload } = args; if (!SHOW_NOTIFICATIONS) { @@ -32,7 +39,7 @@ const notifier = (args: { case signUpRoutine.FAILURE: case signInWithPasswordRoutine.FAILURE: case getInvitationRoutine.FAILURE: { - message = payload?.error?.message ?? 'An unexpected error occured'; + message = getErrorMessage(payload.error); break; } case signInRoutine.SUCCESS: diff --git a/vite.config.ts b/vite.config.ts index 87c3935d..856eda25 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -19,6 +19,9 @@ const config = ({ mode }: { mode: string }): UserConfigExport => { ignored: ['**/coverage/**'], }, }, + preview: { + port: parseInt(process.env.VITE_PORT || '3001', 10), + }, build: { outDir: 'build', }, @@ -35,14 +38,14 @@ const config = ({ mode }: { mode: string }): UserConfigExport => { requireEnv: false, checkProd: true, }), - ...(mode === 'dev' + ...(mode === 'development' ? [ visualizer({ template: 'treemap', // or sunburst open: true, gzipSize: true, brotliSize: true, - filename: 'analice.html', + filename: 'bundle_analysis.html', }) as PluginOption, ] : []), diff --git a/yarn.lock b/yarn.lock index 669b1a9f..f5f02323 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3118,9 +3118,9 @@ __metadata: languageName: node linkType: hard -"@graasp/query-client@npm:1.4.0": - version: 1.4.0 - resolution: "@graasp/query-client@npm:1.4.0" +"@graasp/query-client@npm:1.4.1": + version: 1.4.1 + resolution: "@graasp/query-client@npm:1.4.1" dependencies: "@graasp/sdk": 1.2.0 "@graasp/translations": 1.18.1 @@ -3133,7 +3133,7 @@ __metadata: uuid: 9.0.0 peerDependencies: react: ^17.0.0 - checksum: d5581682e607a3275c05ee351987afe490086c06ef078d50aa8c6e2b4662844f9ae722ec925f3aa9bd91c1a68da8b0dea1c6293d263fbed23939156dfe60f90f + checksum: 95d97d12d4d8fee4c06fbce468edd58909e35b63a05e34de4a5cf44d9f5f2246bfae296e97cbef04e72e46160b53059a757aac2118c9074e647f4781efc34705 languageName: node linkType: hard @@ -8608,7 +8608,7 @@ __metadata: "@emotion/cache": 11.10.8 "@emotion/react": 11.11.1 "@emotion/styled": 11.11.0 - "@graasp/query-client": 1.4.0 + "@graasp/query-client": 1.4.1 "@graasp/sdk": 1.2.0 "@graasp/translations": 1.18.0 "@graasp/ui": 3.3.0