From eeba2b74592a522564a596da0a83e4b5d3e1d2d0 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 14 Sep 2024 00:22:43 +0000 Subject: [PATCH] moved error handling to middleware --- package.json | 1 + pnpm-lock.yaml | 15 ++++++++++ src/api/controllers/TimetableApi.ts | 29 +++++-------------- src/api/controllers/auth/AuthApi.ts | 19 ++++-------- src/api/controllers/auth/decorators.ts | 15 +++++----- src/api/index.ts | 15 ++++++++++ src/components/IrdomAuthButton.vue | 6 ++-- src/components/RegistrationForm.vue | 20 +++++-------- src/router/auth.ts | 6 ++-- src/store/profile.ts | 5 +--- src/utils/errorHandler.ts | 25 +++++++++++----- .../admin/achievement/AchievementListView.vue | 6 ++-- .../achievement/AchievementRecieversView.vue | 11 +++---- src/views/admin/group/AdminGroupView.vue | 5 +--- src/views/admin/groups/AdminGroupsView.vue | 11 ++----- src/views/admin/groups/GroupTreeNode.vue | 6 +--- src/views/admin/scopes/AdminScopesView.vue | 5 +--- src/views/apps/AsyncContent.vue | 6 ++-- src/views/auth/AddEmailView.vue | 5 +--- src/views/auth/ChangeEmailView.vue | 5 +--- src/views/auth/OauthRegisterView.vue | 5 +--- src/views/profile/ProfileEditView.vue | 5 +--- src/views/profile/ProfileSettingsView.vue | 5 +--- src/views/profile/ProfileView.vue | 16 ++-------- 24 files changed, 103 insertions(+), 144 deletions(-) diff --git a/package.json b/package.json index 1f491512..193b729b 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@profcomff/api-uilib": "2024.7.28", "axios": "^1.7.5", "markdown-it": "^14.1.0", + "openapi-fetch": "^0.12.0", "pinia": "^2.2.2", "query-string": "^9.1.0", "ua-parser-js": "^1.0.38", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 214d397b..ef328c9e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: markdown-it: specifier: ^14.1.0 version: 14.1.0 + openapi-fetch: + specifier: ^0.12.0 + version: 0.12.0 pinia: specifier: ^2.2.2 version: 2.2.2(typescript@5.3.3)(vue@3.4.38(typescript@5.3.3)) @@ -2674,9 +2677,15 @@ packages: openapi-fetch@0.10.6: resolution: {integrity: sha512-6xXfvIEL/POtLGOaFPsp3O+pDe+J3DZYxbD9BrsQHXOTeNK8z/gsWHT6adUy1KcpQOhmkerMzlQrJM6DbN55dQ==} + openapi-fetch@0.12.0: + resolution: {integrity: sha512-D/g5BUGiOAKqivR5s02veJ2+cMHzrkFJKberKP4Z8Vl2VhE6MMirI6wWOgpp8wlsYCRRK7CX0NCGVL/mt6l1fA==} + openapi-typescript-helpers@0.0.11: resolution: {integrity: sha512-xofUHlVFq+BMquf3nh9I8N2guHckW6mrDO/F3kaFgrL7MGbjldDnQ9TIT+rkH/+H0LiuO+RuZLnNmsJwsjwUKg==} + openapi-typescript-helpers@0.0.13: + resolution: {integrity: sha512-z44WK2e7ygW3aUtAtiurfEACohf/Qt9g6BsejmIYgEoY4REHeRzgFJmO3ium0libsuzPc145I+8lE9aiiZrQvQ==} + openapi-typescript@7.4.0: resolution: {integrity: sha512-u4iVuTGkzKG4rHFUMA/IFXTks9tYVQzkowZsScMOdzJSvIF10qSNySWHTwnN2fD+MEeWFAM8i1f3IUBlgS92eQ==} hasBin: true @@ -6510,8 +6519,14 @@ snapshots: dependencies: openapi-typescript-helpers: 0.0.11 + openapi-fetch@0.12.0: + dependencies: + openapi-typescript-helpers: 0.0.13 + openapi-typescript-helpers@0.0.11: {} + openapi-typescript-helpers@0.0.13: {} + openapi-typescript@7.4.0(typescript@5.3.3): dependencies: '@redocly/openapi-core': 1.22.1(supports-color@9.4.0) diff --git a/src/api/controllers/TimetableApi.ts b/src/api/controllers/TimetableApi.ts index 0a835d8a..6316cc2c 100644 --- a/src/api/controllers/TimetableApi.ts +++ b/src/api/controllers/TimetableApi.ts @@ -1,7 +1,6 @@ import { stringifyDate, getDateWithDayOffset } from './../../utils/date'; import { useTimetableStore } from './../../store/timetable'; import apiClient from '@/api/'; -import { recordError } from '@/utils/errorHandler'; interface GetLecturersParams { query?: string; @@ -36,73 +35,61 @@ function getLecturers(params?: GetLecturersParams) { export class TimetableApi { public static async getLecturer(id: number) { const { setLecturers } = useTimetableStore(); - const { data, error } = await getLecturer(id); + const { data } = await getLecturer(id); if (data) { setLecturers([data]); - } else { - recordError(error); } } public static async getLecturers() { const { setLecturers } = useTimetableStore(); - const { data, error } = await getLecturers(); + const { data } = await getLecturers(); if (data) { setLecturers(data.items); - } else { - recordError(error); } } public static async getRoom(id: number) { const { setRooms } = useTimetableStore(); - const { data, error } = await apiClient.GET('/timetable/room/{id}', { + const { data } = await apiClient.GET('/timetable/room/{id}', { params: { path: { id } }, }); if (data) { setRooms([data]); - } else { - recordError(error); } } public static async getRooms() { const { setRooms } = useTimetableStore(); - const { data, error } = await apiClient.GET('/timetable/room/'); + const { data } = await apiClient.GET('/timetable/room/'); if (data) { setRooms(data.items); - } else { - recordError(error); } } public static async getEvent(id: number) { const { setEvents } = useTimetableStore(); - const { data, error } = await apiClient.GET('/timetable/event/{id}', { + const { data } = await apiClient.GET('/timetable/event/{id}', { params: { path: { id } }, }); if (data) { setEvents([data]); - } else { - recordError(error); } } public static async getEvents(params?: GetEventsParams) { const { setEvents } = useTimetableStore(); - const { data, error } = await apiClient.GET('/timetable/event/', { + const { data } = await apiClient.GET('/timetable/event/', { params: { query: params }, }); if (data && data !== null) { setEvents(data.items); - } else { - recordError(error); } } public static async getDayEvents(date: Date, groupId: number) { const { setDay } = useTimetableStore(); - const { data, error } = await apiClient.GET('/timetable/event/', { + const { data } = await apiClient.GET('/timetable/event/', { params: { query: { start: stringifyDate(date), @@ -113,8 +100,6 @@ export class TimetableApi { }); if (data && data !== null) { setDay(date, data.items); - } else { - recordError(error); } } diff --git a/src/api/controllers/auth/AuthApi.ts b/src/api/controllers/auth/AuthApi.ts index d1ee01c0..50d813f3 100644 --- a/src/api/controllers/auth/AuthApi.ts +++ b/src/api/controllers/auth/AuthApi.ts @@ -5,7 +5,7 @@ import { scopename } from '@/models/ScopeName'; import { useProfileStore } from '@/store/profile'; import { LocalStorage, LocalStorageItem } from '@/models/LocalStorage'; import { UNKNOWN_DEVICE } from '@/models'; -import { recordError } from '@/utils/errorHandler'; + import router from '@/router'; import apiClient from '@/api/'; @@ -32,29 +32,24 @@ export type UserSessionById = export class AuthApi { static getScopes = apply(async () => { const { setScopes } = useAuthStore(); - const { data, error } = await apiClient.GET('/auth/scope'); + const { data } = await apiClient.GET('/auth/scope'); if (data) { setScopes(data); - } else { - recordError(error); } }, [scoped, scopename.auth.scope.read]); static getUser = apply( async (id: number, info: UserInfo[] = []) => { const { setUsers } = useAuthStore(); - const { response, data, error } = await apiClient.GET('/auth/user/{user_id}', { + const { data } = await apiClient.GET('/auth/user/{user_id}', { params: { path: { user_id: id }, query: { info }, }, }); - console.log(response); if (data) { setUsers([data]); - } else { - recordError(error); } }, [scoped, scopename.auth.user.read] @@ -63,13 +58,11 @@ export class AuthApi { static getUsers = apply( async (info: UserInfo[] = []) => { const { setUsers } = useAuthStore(); - const { data, error } = await apiClient.GET('/auth/user', { + const { data } = await apiClient.GET('/auth/user', { params: { query: { info } }, }); if (data) { setUsers(data.items); - } else { - recordError(error); } }, [scoped, scopename.auth.user.read] @@ -91,7 +84,7 @@ export class AuthApi { const promise = apiClient.GET('/auth/me', { params: { query: { info } }, }); - const { data, error } = await promise; + const { data } = await promise; if (data) { profileStore.id = data.id; @@ -116,8 +109,6 @@ export class AuthApi { } profileStore.updateTokenScopes(); - } else { - recordError(error); } return promise; diff --git a/src/api/controllers/auth/decorators.ts b/src/api/controllers/auth/decorators.ts index d20dc5ba..a141a34f 100644 --- a/src/api/controllers/auth/decorators.ts +++ b/src/api/controllers/auth/decorators.ts @@ -4,6 +4,7 @@ import { ToastType } from '@/models'; import router from '@/router'; import { useProfileStore } from '@/store/profile'; import { useToastStore } from '@/store/toast'; +import { apiError } from '@/utils/errorHandler'; export type Func = (...args: FuncArgs) => R; type Decorator = Func< @@ -42,17 +43,17 @@ export function showErrorToast( try { const response = await method(...args); return response; - } catch (error) { - console.log(error); + } catch (err) { + const error = err as apiError; if (error) { toastStore.push({ - title: error.msg ?? error.ru, + title: error.ru ?? error.message, type: ToastType.Error, }); } else { toastStore.push({ title: 'Неизвестная ошибка', - description: error instanceof Error ? error.message : '', + description: '', type: ToastType.Error, }); } @@ -67,9 +68,9 @@ export function checkToken>( try { const { error } = await apiClient.GET('/auth/me'); throw error; - } catch (error) { - console.log(error); - if (error && error.msg === 'Forbidden') { + } catch (err) { + const error = err as apiError; + if (error && error.message === 'Forbidden') { const { deleteToken } = useProfileStore(); const toastStore = useToastStore(); deleteToken(); diff --git a/src/api/index.ts b/src/api/index.ts index 7adb9bcf..cf6c3ad5 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,5 +1,20 @@ export * from './controllers'; +import { recordError } from '@/utils/errorHandler'; import { createClient } from '@profcomff/api-uilib'; +import { type Middleware } from 'openapi-fetch'; + +const responseMiddleware: Middleware = { + async onResponse({ response }) { + const data = await response.clone(); + if (!response.ok) { + const error = await data.json(); + recordError(response.url, response.status, await error); + return undefined; + } + return response; + }, +}; const apiClient = createClient(import.meta.env.VITE_API_URL); +apiClient.use(responseMiddleware); export default apiClient; diff --git a/src/components/IrdomAuthButton.vue b/src/components/IrdomAuthButton.vue index 7282505b..e073a6a3 100644 --- a/src/components/IrdomAuthButton.vue +++ b/src/components/IrdomAuthButton.vue @@ -1,7 +1,7 @@ diff --git a/src/router/auth.ts b/src/router/auth.ts index bdf6ee12..26948359 100644 --- a/src/router/auth.ts +++ b/src/router/auth.ts @@ -5,7 +5,7 @@ import { useProfileStore } from '@/store/profile'; import { useToastStore } from '@/store/toast'; import { AuthApi } from '@/api'; import { AuthMethodName } from '@/models'; -import { recordError } from '@/utils/errorHandler'; + import apiClient from '@/api/'; export const authRoutes: RouteRecordRaw[] = [ @@ -63,7 +63,7 @@ export const authHandler: NavigationGuard = async to => { replace: true, }; } - const { data, error } = profileStore.isUserLogged + const { data } = profileStore.isUserLogged ? await apiClient.POST(`/auth/${methodName}/registration`, { body: { ...to.query, @@ -82,8 +82,6 @@ export const authHandler: NavigationGuard = async to => { profileStore.updateToken(); toastStore.push({ title: 'Вы успешно вошли в аккаунт' }); return { path: '/profile', replace: true }; - } else { - recordError(error); } return { path: '/auth/error', query: { text: 'Непредвиденная ошибка' }, replace: true }; } catch (error) { diff --git a/src/store/profile.ts b/src/store/profile.ts index c9396d29..e36dfc6b 100644 --- a/src/store/profile.ts +++ b/src/store/profile.ts @@ -4,7 +4,6 @@ import { LocalStorage, LocalStorageItem } from '@/models/LocalStorage'; import { defineStore } from 'pinia'; import { computed, ref } from 'vue'; import apiClient from '@/api/'; -import { recordError } from '@/utils/errorHandler'; export const useProfileStore = defineStore('profile', () => { const id = ref(null); @@ -57,7 +56,7 @@ export const useProfileStore = defineStore('profile', () => { if (newMarketingId) { marketingId.value = newMarketingId; } else if (item === null) { - const { data, error } = await apiClient.POST('/marketing/v1/user'); + const { data } = await apiClient.POST('/marketing/v1/user'); if (data) { LocalStorage.set(LocalStorageItem.MarketingId, data.id); marketingId.value = data.id; @@ -68,8 +67,6 @@ export const useProfileStore = defineStore('profile', () => { additional_data: JSON.stringify(data), }, }); - } else { - recordError(error); } } else { marketingId.value = +item; diff --git a/src/utils/errorHandler.ts b/src/utils/errorHandler.ts index f3d7e5eb..945890ab 100644 --- a/src/utils/errorHandler.ts +++ b/src/utils/errorHandler.ts @@ -1,17 +1,28 @@ import apiClient from '@/api'; -import { components } from '@profcomff/api-uilib/src/openapi/auth'; -export type apiError = - | components['schemas']['ValidationError'] - | components['schemas']['HTTPValidationError']; +export type apiError = { + status: string; + message: string; + ru: string; +}; -export function recordError(error: apiError | undefined) { - console.log('error: ', error); +interface ErrorInfo { + url: string; + status: number; + message: string; +} + +export function recordError(url: string, status: number, error: apiError | undefined) { if (error) { + const errorInfo: ErrorInfo = { + url, + status, + message: error.message, + }; apiClient.POST('/marketing/v1/action', { body: { action: 'error', - additional_data: JSON.stringify(error), + additional_data: JSON.stringify(errorInfo), }, }); } diff --git a/src/views/admin/achievement/AchievementListView.vue b/src/views/admin/achievement/AchievementListView.vue index 861ec9e9..9d99de6b 100644 --- a/src/views/admin/achievement/AchievementListView.vue +++ b/src/views/admin/achievement/AchievementListView.vue @@ -6,7 +6,7 @@ import AccessRestricted from '@/components/AccessRestricted.vue'; import IrdomLayout from '@/components/IrdomLayout.vue'; import { scopename } from '@/models/ScopeName'; import { useToolbar } from '@/store/toolbar'; -import { recordError } from '@/utils/errorHandler'; + import apiClient from '@/api/'; const toolbar = useToolbar(); @@ -20,11 +20,9 @@ const newPic = ref(undefined); const created = ref(undefined); onMounted(async () => { - const { data, error } = await apiClient.GET('/achievement/achievement'); + const { data } = await apiClient.GET('/achievement/achievement'); if (data) { achievements.value = data; - } else { - recordError(error); } }); diff --git a/src/views/admin/achievement/AchievementRecieversView.vue b/src/views/admin/achievement/AchievementRecieversView.vue index 244934a9..52974d2c 100644 --- a/src/views/admin/achievement/AchievementRecieversView.vue +++ b/src/views/admin/achievement/AchievementRecieversView.vue @@ -7,7 +7,7 @@ import IrdomLayout from '@/components/IrdomLayout.vue'; import { scopename } from '@/models/ScopeName'; import { useToolbar } from '@/store/toolbar'; import { getPictureUrl } from '@/utils/achievement'; -import { recordError } from '@/utils/errorHandler'; + import apiClient from '@/api/'; const route = useRoute(); @@ -23,14 +23,11 @@ const achievement = ref(); const giveTo = ref(); onMounted(async () => { - const { data, error } = await apiClient.GET( - '/achievement/achievement/{achievement_id}/reciever', - { params: { path: { achievement_id: achievementId.value } } } - ); + const { data } = await apiClient.GET('/achievement/achievement/{achievement_id}/reciever', { + params: { path: { achievement_id: achievementId.value } }, + }); if (data) { achievement.value = data; - } else { - recordError(error); } }); diff --git a/src/views/admin/group/AdminGroupView.vue b/src/views/admin/group/AdminGroupView.vue index 4859a6e3..023ee4fa 100644 --- a/src/views/admin/group/AdminGroupView.vue +++ b/src/views/admin/group/AdminGroupView.vue @@ -10,7 +10,6 @@ import { scopename } from '@/models/ScopeName'; import { useAuthStore } from '@/store/auth'; import { useProfileStore } from '@/store/profile'; import { useToolbar } from '@/store/toolbar'; -import { recordError } from '@/utils/errorHandler'; const profileStore = useProfileStore(); const toolbar = useToolbar(); @@ -31,7 +30,7 @@ onMounted(async () => { AuthApi.getScopes(); if (!group.value) { - const { data, error } = await apiClient.GET('/auth/group/{id}', { + const { data } = await apiClient.GET('/auth/group/{id}', { params: { path: { id: groupId.value }, query: { info: ['scopes'] }, @@ -39,8 +38,6 @@ onMounted(async () => { }); if (data) { authStore.setGroup(data); - } else { - recordError(error); } } }); diff --git a/src/views/admin/groups/AdminGroupsView.vue b/src/views/admin/groups/AdminGroupsView.vue index 55b6f5ce..5786f45a 100644 --- a/src/views/admin/groups/AdminGroupsView.vue +++ b/src/views/admin/groups/AdminGroupsView.vue @@ -6,7 +6,7 @@ import IrdomLayout from '@/components/IrdomLayout.vue'; import { useToolbar } from '@/store/toolbar'; import { useProfileStore } from '@/store/profile'; import { scopename } from '@/models/ScopeName'; -import { recordError } from '@/utils/errorHandler'; + import apiClient from '@/api/'; const authStore = useAuthStore(); @@ -21,7 +21,7 @@ toolbar.setup({ onMounted(async () => { if (authStore.groups.size === 0) { - const { data, error } = await apiClient.GET('/auth/group', { + const { data } = await apiClient.GET('/auth/group', { params: { query: { info: ['scopes', 'child'] } }, }); if (data) { @@ -31,8 +31,6 @@ onMounted(async () => { } authStore.setGroup(group); } - } else { - recordError(error); } } }); @@ -45,18 +43,15 @@ const createGroup = async (e: Event) => { const name = formData.get('new-group-name')!.toString(); if (profileStore.isUserLogged) { - const { data, error } = await apiClient.POST('/auth/group', { + const { data } = await apiClient.POST('/auth/group', { body: { name, parent_id: null, scopes: [], }, }); - if (data) { authStore.setGroup(data); - } else { - recordError(error); } form.reset(); diff --git a/src/views/admin/groups/GroupTreeNode.vue b/src/views/admin/groups/GroupTreeNode.vue index 28275bb5..5f26e229 100644 --- a/src/views/admin/groups/GroupTreeNode.vue +++ b/src/views/admin/groups/GroupTreeNode.vue @@ -5,7 +5,6 @@ import { StoreGroup, useAuthStore } from '@/store/auth'; import { useProfileStore } from '@/store/profile'; import { ref } from 'vue'; import { VExpansionPanel } from 'vuetify/components'; -import { recordError } from '@/utils/errorHandler'; const props = withDefaults(defineProps<{ node: StoreGroup | null; indentSize?: number }>(), { indentSize: 32, @@ -26,18 +25,15 @@ const createGroup = async (e: Event) => { const group = authStore.groups.get(parentId); if (profileStore.isUserLogged && group) { - const { data, error } = await apiClient.POST('/auth/group', { + const { data } = await apiClient.POST('/auth/group', { body: { name, parent_id: group.id, scopes: [], }, }); - if (data) { authStore.setGroup(data); - } else { - recordError(error); } form.reset(); diff --git a/src/views/admin/scopes/AdminScopesView.vue b/src/views/admin/scopes/AdminScopesView.vue index 5fc759e0..6d12b5f2 100644 --- a/src/views/admin/scopes/AdminScopesView.vue +++ b/src/views/admin/scopes/AdminScopesView.vue @@ -9,7 +9,6 @@ import { useAuthStore } from '@/store/auth'; import { useProfileStore } from '@/store/profile'; import { useToolbar } from '@/store/toolbar'; import apiClient from '@/api/'; -import { recordError } from '@/utils/errorHandler'; const authStore = useAuthStore(); const profileStore = useProfileStore(); @@ -44,15 +43,13 @@ const createScope = async (e: Event) => { const name = formData.get('name')?.toString(); if (name && profileStore.isUserLogged) { - const { data, error } = await apiClient.POST('/auth/scope', { + const { data } = await apiClient.POST('/auth/scope', { body: { comment, name }, }); form.reset(); if (data) { authStore.setScopes([data]); - } else { - recordError(error); } } } diff --git a/src/views/apps/AsyncContent.vue b/src/views/apps/AsyncContent.vue index 545d1034..ae7b324e 100644 --- a/src/views/apps/AsyncContent.vue +++ b/src/views/apps/AsyncContent.vue @@ -4,7 +4,7 @@ import { useAppsStore } from '@/store/apps'; import { useProfileStore } from '@/store/profile'; import { useToastStore } from '@/store/toast'; import { RouterLink } from 'vue-router'; -import { recordError } from '@/utils/errorHandler'; + import apiClient from '@/api/'; const appsStore = useAppsStore(); @@ -12,13 +12,11 @@ const profileStore = useProfileStore(); const toastStore = useToastStore(); if (!appsStore.categories) { - const { data, error } = await apiClient.GET('/services/category', { + const { data } = await apiClient.GET('/services/category', { params: { query: { info: ['buttons'] } }, }); if (data) { useAppsStore().categories = data; - } else { - recordError(error); } } diff --git a/src/views/auth/AddEmailView.vue b/src/views/auth/AddEmailView.vue index 08953c33..c912c172 100644 --- a/src/views/auth/AddEmailView.vue +++ b/src/views/auth/AddEmailView.vue @@ -5,7 +5,6 @@ import { useRouter } from 'vue-router'; import IrdomLayout from '@/components/IrdomLayout.vue'; import { useToastStore } from '@/store/toast'; import { useToolbar } from '@/store/toolbar'; -import { recordError } from '@/utils/errorHandler'; const toolbar = useToolbar(); @@ -35,7 +34,7 @@ const submitHandler = async (event: Event) => { }); } if (email && newPassword && newPassword == repeatPassword) { - const { data, error } = await AuthApi.registerEmail(email, newPassword); + const { data } = await AuthApi.registerEmail(email, newPassword); if (data) { if (data.status == 'Success') { toastStore.push({ @@ -46,8 +45,6 @@ const submitHandler = async (event: Event) => { emit('success'); } router.push('/profile'); - } else { - recordError(error); } } }; diff --git a/src/views/auth/ChangeEmailView.vue b/src/views/auth/ChangeEmailView.vue index 27018e24..98aa0dab 100644 --- a/src/views/auth/ChangeEmailView.vue +++ b/src/views/auth/ChangeEmailView.vue @@ -6,7 +6,6 @@ import { useRouter } from 'vue-router'; import IrdomLayout from '@/components/IrdomLayout.vue'; import { useToastStore } from '@/store/toast'; import { useToolbar } from '@/store/toolbar'; -import { recordError } from '@/utils/errorHandler'; const toolbar = useToolbar(); @@ -22,7 +21,7 @@ const toastStore = useToastStore(); const current_email = ref(''); onMounted(async () => { - const { data, error } = await AuthApi.getMe([ + const { data } = await AuthApi.getMe([ 'auth_methods', 'groups', 'indirect_groups', @@ -31,8 +30,6 @@ onMounted(async () => { ]); if (data?.email) { current_email.value = data.email; - } else { - recordError(error); } }); diff --git a/src/views/auth/OauthRegisterView.vue b/src/views/auth/OauthRegisterView.vue index ae859ce5..00d3ac90 100644 --- a/src/views/auth/OauthRegisterView.vue +++ b/src/views/auth/OauthRegisterView.vue @@ -6,7 +6,6 @@ import { useToolbar } from '@/store/toolbar'; import { useProfileStore } from '@/store/profile'; import { AuthMethodName } from '@/models'; import apiClient from '@/api/'; -import { recordError } from '@/utils/errorHandler'; const router = useRouter(); const toolbar = useToolbar(); @@ -26,7 +25,7 @@ async function handleAccept() { return router.replace({ path: '/auth/error', query: { text: 'Непредвиденная ошибка' } }); } - const { data, error } = await apiClient.POST(`/auth/${idTokenIssuer}/registration`, { + const { data } = await apiClient.POST(`/auth/${idTokenIssuer}/registration`, { body: { id_token: idToken, session_name: navigator.userAgent ?? 'unknown_device', @@ -36,8 +35,6 @@ async function handleAccept() { localStorage.setItem('token', data.token); profileStore.updateToken(); return router.replace({ path: '/profile' }); - } else { - recordError(error); } } catch (error) { if (isAxiosError(error) && error.response?.status == 401) { diff --git a/src/views/profile/ProfileEditView.vue b/src/views/profile/ProfileEditView.vue index 3ad34c7e..1bbe014c 100644 --- a/src/views/profile/ProfileEditView.vue +++ b/src/views/profile/ProfileEditView.vue @@ -14,7 +14,6 @@ import { useProfileStore } from '@/store/profile'; import { UserdataConverter } from '@/utils/UserdataConverter'; import { useRouter } from 'vue-router'; import { useToolbar } from '@/store/toolbar'; -import { recordError } from '@/utils/errorHandler'; const profileStore = useProfileStore(); const router = useRouter(); @@ -71,7 +70,7 @@ onMounted(async () => { }); async function saveEdit() { - const { data, error } = await AuthApi.getMe([ + const { data } = await AuthApi.getMe([ 'auth_methods', 'groups', 'indirect_groups', @@ -88,8 +87,6 @@ async function saveEdit() { if (data) { await UserdataApi.patchUserById(data.id, updateBody); router.push('/profile'); - } else { - recordError(error); } } diff --git a/src/views/profile/ProfileSettingsView.vue b/src/views/profile/ProfileSettingsView.vue index 773d6a36..d856a5fd 100644 --- a/src/views/profile/ProfileSettingsView.vue +++ b/src/views/profile/ProfileSettingsView.vue @@ -4,14 +4,13 @@ import { useRouter } from 'vue-router'; import IrdomLayout from '@/components/IrdomLayout.vue'; import { useToolbar } from '@/store/toolbar'; import { onMounted, ref } from 'vue'; -import { recordError } from '@/utils/errorHandler'; const router = useRouter(); const toolbar = useToolbar(); const current_email = ref(); onMounted(async () => { - const { data, error } = await AuthApi.getMe([ + const { data } = await AuthApi.getMe([ 'auth_methods', 'groups', 'indirect_groups', @@ -20,8 +19,6 @@ onMounted(async () => { ]); if (data) { current_email.value = data.email; - } else { - recordError(error); } }); diff --git a/src/views/profile/ProfileView.vue b/src/views/profile/ProfileView.vue index 76833bb7..e55d57e6 100644 --- a/src/views/profile/ProfileView.vue +++ b/src/views/profile/ProfileView.vue @@ -10,7 +10,6 @@ import { useProfileStore } from '@/store/profile'; import { UserdataConverter } from '@/utils/UserdataConverter'; import { ToolbarActionItem } from '@/components/IrdomToolbar.vue'; import { useToolbar } from '@/store/toolbar'; -import { recordError } from '@/utils/errorHandler'; import FullscreenLoader from '@/components/FullscreenLoader.vue'; const profileStore = useProfileStore(); @@ -21,11 +20,7 @@ const toolbar = useToolbar(); const isOwnProfile = !('id' in route.params) || route.params.id === undefined; const buttons: ToolbarActionItem[] = []; -// buttons.push({ -// icon: 'edit', -// ariaLabel: 'Редактировать профиль', -// onClick: () => router.push('/profile/edit'), -// }); + if (isOwnProfile) { buttons.push({ icon: 'settings', @@ -69,7 +64,7 @@ const loadUserdata = async () => { userdataLoadingState.value = UserdataLoadingState.Loading; - const { data: me, error: meError } = await (isOwnProfile + const { data: me } = await (isOwnProfile ? AuthApi.getMe(['auth_methods', 'groups', 'indirect_groups', 'session_scopes', 'user_scopes']) : AuthApi.getById(Number(route.params.id), [ 'auth_methods', @@ -79,8 +74,7 @@ const loadUserdata = async () => { ])); if (me) { - const { data, error } = await UserdataApi.getUser(me.id); - console.log(data); + const { data } = await UserdataApi.getUser(me.id); if (data) { fullName.value = data.items.find( @@ -98,11 +92,7 @@ const loadUserdata = async () => { userdata.value = UserdataConverter.flatToArray(data); userdataLoadingState.value = UserdataLoadingState.Ready; - } else { - recordError(error); } - } else { - recordError(meError); } };