1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-24 20:36:40 +07:00

rename some items

This commit is contained in:
Fedor Katurov 2023-11-17 23:24:33 +06:00
parent afc04abfd4
commit 865de09ad9
12 changed files with 119 additions and 89 deletions

View file

@ -1,5 +1,8 @@
import { TelegramUser } from '@v9v/ts-react-telegram-login'; import { TelegramUser } from '@v9v/ts-react-telegram-login';
import { API } from '~/constants/api';
import { api, unwrap } from '~/utils/api';
import { import {
ApiAttachSocialRequest, ApiAttachSocialRequest,
ApiAttachSocialResult, ApiAttachSocialResult,
@ -22,24 +25,20 @@ import {
ApiUpdateUserResult, ApiUpdateUserResult,
ApiUserLoginRequest, ApiUserLoginRequest,
ApiUserLoginResult, ApiUserLoginResult,
} from '~/api/auth/types'; } from './types';
import { API } from '~/constants/api';
import { api, cleanResult } from '~/utils/api';
export const apiUserLogin = ({ username, password }: ApiUserLoginRequest) => export const apiUserLogin = ({ username, password }: ApiUserLoginRequest) =>
api api
.post<ApiUserLoginResult>(API.USER.LOGIN, { username, password }) .post<ApiUserLoginResult>(API.USER.LOGIN, { username, password })
.then(cleanResult); .then(unwrap);
export const apiAuthGetUser = () => export const apiAuthGetUser = () =>
api.get<ApiAuthGetUserResult>(API.USER.ME).then(cleanResult); api.get<ApiAuthGetUserResult>(API.USER.ME).then(unwrap);
export const apiAuthGetUserProfile = ({ export const apiAuthGetUserProfile = ({
username, username,
}: ApiAuthGetUserProfileRequest) => }: ApiAuthGetUserProfileRequest) =>
api api.get<ApiAuthGetUserProfileResult>(API.USER.PROFILE(username)).then(unwrap);
.get<ApiAuthGetUserProfileResult>(API.USER.PROFILE(username))
.then(cleanResult);
export const apiAuthGetUpdates = ({ export const apiAuthGetUpdates = ({
exclude_dialogs, exclude_dialogs,
@ -49,44 +48,40 @@ export const apiAuthGetUpdates = ({
.get<ApiAuthGetUpdatesResult>(API.USER.GET_UPDATES, { .get<ApiAuthGetUpdatesResult>(API.USER.GET_UPDATES, {
params: { exclude_dialogs, last }, params: { exclude_dialogs, last },
}) })
.then(cleanResult); .then(unwrap);
export const apiUpdateUser = ({ user }: ApiUpdateUserRequest) => export const apiUpdateUser = ({ user }: ApiUpdateUserRequest) =>
api.patch<ApiUpdateUserResult>(API.USER.ME, user).then(cleanResult); api.patch<ApiUpdateUserResult>(API.USER.ME, user).then(unwrap);
export const apiUpdatePhoto = ({ file }: ApiUpdatePhotoRequest) => export const apiUpdatePhoto = ({ file }: ApiUpdatePhotoRequest) =>
api.post<ApiUpdateUserResult>(API.USER.UPDATE_PHOTO, file).then(cleanResult); api.post<ApiUpdateUserResult>(API.USER.UPDATE_PHOTO, file).then(unwrap);
export const apiUpdateCover = ({ file }: ApiUpdatePhotoRequest) => export const apiUpdateCover = ({ file }: ApiUpdatePhotoRequest) =>
api.post<ApiUpdateUserResult>(API.USER.UPDATE_COVER, file).then(cleanResult); api.post<ApiUpdateUserResult>(API.USER.UPDATE_COVER, file).then(unwrap);
export const apiRequestRestoreCode = (field: string) => export const apiRequestRestoreCode = (field: string) =>
api api.post<{ field: string }>(API.USER.REQUEST_CODE(), { field }).then(unwrap);
.post<{ field: string }>(API.USER.REQUEST_CODE(), { field })
.then(cleanResult);
export const apiCheckRestoreCode = ({ code }: ApiCheckRestoreCodeRequest) => export const apiCheckRestoreCode = ({ code }: ApiCheckRestoreCodeRequest) =>
api api.get<ApiCheckRestoreCodeResult>(API.USER.REQUEST_CODE(code)).then(unwrap);
.get<ApiCheckRestoreCodeResult>(API.USER.REQUEST_CODE(code))
.then(cleanResult);
export const apiRestoreCode = ({ code, password }: ApiRestoreCodeRequest) => export const apiRestoreCode = ({ code, password }: ApiRestoreCodeRequest) =>
api api
.put<ApiRestoreCodeResult>(API.USER.REQUEST_CODE(code), { password }) .put<ApiRestoreCodeResult>(API.USER.REQUEST_CODE(code), { password })
.then(cleanResult); .then(unwrap);
export const apiGetSocials = () => export const apiGetSocials = () =>
api.get<ApiGetSocialsResult>(API.USER.GET_SOCIALS).then(cleanResult); api.get<ApiGetSocialsResult>(API.USER.GET_SOCIALS).then(unwrap);
export const apiDropSocial = ({ id, provider }: ApiDropSocialRequest) => export const apiDropSocial = ({ id, provider }: ApiDropSocialRequest) =>
api api
.delete<ApiDropSocialResult>(API.USER.DROP_SOCIAL(provider, id)) .delete<ApiDropSocialResult>(API.USER.DROP_SOCIAL(provider, id))
.then(cleanResult); .then(unwrap);
export const apiAttachSocial = ({ token }: ApiAttachSocialRequest) => export const apiAttachSocial = ({ token }: ApiAttachSocialRequest) =>
api api
.post<ApiAttachSocialResult>(API.USER.ATTACH_SOCIAL, { token }) .post<ApiAttachSocialResult>(API.USER.ATTACH_SOCIAL, { token })
.then(cleanResult); .then(unwrap);
export const apiLoginWithSocial = ({ export const apiLoginWithSocial = ({
token, token,
@ -99,7 +94,7 @@ export const apiLoginWithSocial = ({
username, username,
password, password,
}) })
.then(cleanResult); .then(unwrap);
export const apiAttachTelegram = (data: TelegramUser) => export const apiAttachTelegram = (data: TelegramUser) =>
api.post(API.USER.ATTACH_TELEGRAM, data); api.post(API.USER.ATTACH_TELEGRAM, data);

View file

@ -2,16 +2,16 @@ import axios from 'axios';
import { API } from '~/constants/api'; import { API } from '~/constants/api';
import { IGetGithubIssuesResult, StatBackend } from '~/types/boris'; import { IGetGithubIssuesResult, StatBackend } from '~/types/boris';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
export const getBorisBackendStats = () => export const getBorisBackendStats = () =>
api.get<StatBackend>(API.BORIS.GET_BACKEND_STATS).then(cleanResult); api.get<StatBackend>(API.BORIS.GET_BACKEND_STATS).then(unwrap);
export const getGithubIssues = () => { export const getGithubIssues = () => {
return axios return axios
.get<IGetGithubIssuesResult>(API.BORIS.GITHUB_ISSUES, { .get<IGetGithubIssuesResult>(API.BORIS.GITHUB_ISSUES, {
params: { state: 'all', sort: 'created' }, params: { state: 'all', sort: 'created' },
}) })
.then(result => result.data) .then(unwrap)
.catch(() => []); .catch(() => []);
}; };

View file

@ -1,12 +1,12 @@
import { API } from '~/constants/api'; import { API } from '~/constants/api';
import { GetSearchResultsRequest, GetSearchResultsResult } from '~/types/flow'; import { GetSearchResultsRequest, GetSearchResultsResult } from '~/types/flow';
import { PostCellViewRequest, PostCellViewResult } from '~/types/node'; import { PostCellViewRequest, PostCellViewResult } from '~/types/node';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
export const postCellView = ({ id, flow }: PostCellViewRequest) => export const postCellView = ({ id, flow }: PostCellViewRequest) =>
api api
.post<PostCellViewResult>(API.NODES.SET_CELL_VIEW(id), { flow }) .post<PostCellViewResult>(API.NODES.SET_CELL_VIEW(id), { flow })
.then(cleanResult); .then(unwrap);
export const getSearchResults = ({ export const getSearchResults = ({
text, text,
@ -17,4 +17,4 @@ export const getSearchResults = ({
.get<GetSearchResultsResult>(API.SEARCH.NODES, { .get<GetSearchResultsResult>(API.SEARCH.NODES, {
params: { text, skip, take }, params: { text, skip, take },
}) })
.then(cleanResult); .then(unwrap);

View file

@ -5,12 +5,21 @@ import {
GetLabStatsResult, GetLabStatsResult,
GetLabUpdatesResult, GetLabUpdatesResult,
} from '~/types/lab'; } from '~/types/lab';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
export const getLabNodes = ({ offset, limit, sort, search }: GetLabNodesRequest) => export const getLabNodes = ({
offset,
limit,
sort,
search,
}: GetLabNodesRequest) =>
api api
.get<GetLabNodesResult>(API.LAB.NODES, { params: { offset, limit, sort, search } }) .get<GetLabNodesResult>(API.LAB.NODES, {
.then(cleanResult); params: { offset, limit, sort, search },
})
.then(unwrap);
export const getLabStats = () => api.get<GetLabStatsResult>(API.LAB.STATS).then(cleanResult); export const getLabStats = () =>
export const getLabUpdates = () => api.get<GetLabUpdatesResult>(API.LAB.UPDATES).then(cleanResult); api.get<GetLabStatsResult>(API.LAB.STATS).then(unwrap);
export const getLabUpdates = () =>
api.get<GetLabUpdatesResult>(API.LAB.UPDATES).then(unwrap);

View file

@ -7,23 +7,31 @@ import {
ApiSendMessageResult, ApiSendMessageResult,
} from '~/api/messages/types'; } from '~/api/messages/types';
import { API } from '~/constants/api'; import { API } from '~/constants/api';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
export const apiGetUserMessages = ({ username, after, before }: ApiGetUserMessagesRequest) => export const apiGetUserMessages = ({
username,
after,
before,
}: ApiGetUserMessagesRequest) =>
api api
.get<ApiGetUserMessagesResponse>(API.USER.MESSAGES(username), { .get<ApiGetUserMessagesResponse>(API.USER.MESSAGES(username), {
params: { after, before }, params: { after, before },
}) })
.then(cleanResult); .then(unwrap);
export const apiSendMessage = ({ username, message }: ApiSendMessageRequest) => export const apiSendMessage = ({ username, message }: ApiSendMessageRequest) =>
api api
.post<ApiSendMessageResult>(API.USER.MESSAGE_SEND(username), { message }) .post<ApiSendMessageResult>(API.USER.MESSAGE_SEND(username), { message })
.then(cleanResult); .then(unwrap);
export const apiDeleteMessage = ({ username, id, is_locked }: ApiDeleteMessageRequest) => export const apiDeleteMessage = ({
username,
id,
is_locked,
}: ApiDeleteMessageRequest) =>
api api
.delete<ApiDeleteMessageResult>(API.USER.MESSAGE_DELETE(username, id), { .delete<ApiDeleteMessageResult>(API.USER.MESSAGE_DELETE(username, id), {
params: { is_locked }, params: { is_locked },
}) })
.then(cleanResult); .then(unwrap);

View file

@ -1,8 +1,10 @@
import { ApiGetEmbedYoutubeResult } from '~/api/metadata/types'; import { ApiGetEmbedYoutubeResult } from '~/api/metadata/types';
import { API } from '~/constants/api'; import { API } from '~/constants/api';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
export const apiGetEmbedYoutube = (ids: string[]) => export const apiGetEmbedYoutube = (ids: string[]) =>
api api
.get<ApiGetEmbedYoutubeResult>(API.EMBED.YOUTUBE, { params: { ids: ids.join(',') } }) .get<ApiGetEmbedYoutubeResult>(API.EMBED.YOUTUBE, {
.then(cleanResult); params: { ids: ids.join(',') },
})
.then(unwrap);

View file

@ -26,7 +26,7 @@ import {
GetNodeDiffRequest, GetNodeDiffRequest,
GetNodeDiffResult, GetNodeDiffResult,
} from '~/types/node'; } from '~/types/node';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
export type ApiPostNodeRequest = { node: INode }; export type ApiPostNodeRequest = { node: INode };
export type ApiPostNodeResult = { export type ApiPostNodeResult = {
@ -45,7 +45,7 @@ export type ApiGetNodeCommentsResponse = {
}; };
export const apiPostNode = ({ node }: ApiPostNodeRequest) => export const apiPostNode = ({ node }: ApiPostNodeRequest) =>
api.post<ApiPostNodeResult>(API.NODES.SAVE, node).then(cleanResult); api.post<ApiPostNodeResult>(API.NODES.SAVE, node).then(unwrap);
export const getNodeDiff = ({ export const getNodeDiff = ({
start, start,
@ -68,7 +68,7 @@ export const getNodeDiff = ({
with_valid, with_valid,
}, },
}) })
.then(cleanResult); .then(unwrap);
export const apiGetNode = ( export const apiGetNode = (
{ id }: ApiGetNodeRequest, { id }: ApiGetNodeRequest,
@ -76,7 +76,7 @@ export const apiGetNode = (
) => ) =>
api api
.get<ApiGetNodeResponse>(API.NODES.GET(id), config) .get<ApiGetNodeResponse>(API.NODES.GET(id), config)
.then(cleanResult) .then(unwrap)
.then((data) => ({ .then((data) => ({
node: data.node, node: data.node,
last_seen: data.last_seen, last_seen: data.last_seen,
@ -90,13 +90,13 @@ export const apiGetNodeWithCancel = ({ id }: ApiGetNodeRequest) => {
.get<ApiGetNodeResponse>(API.NODES.GET(id), { .get<ApiGetNodeResponse>(API.NODES.GET(id), {
cancelToken: cancelToken.token, cancelToken: cancelToken.token,
}) })
.then(cleanResult), .then(unwrap),
cancel: cancelToken.cancel, cancel: cancelToken.cancel,
}; };
}; };
export const apiPostComment = ({ id, data }: ApiPostCommentRequest) => export const apiPostComment = ({ id, data }: ApiPostCommentRequest) =>
api.post<ApiPostCommentResult>(API.NODES.COMMENT(id), data).then(cleanResult); api.post<ApiPostCommentResult>(API.NODES.COMMENT(id), data).then(unwrap);
export const apiLikeComment = ( export const apiLikeComment = (
nodeId: number, nodeId: number,
@ -110,7 +110,7 @@ export const apiLikeComment = (
data, data,
{ cancelToken: options?.cancelToken }, { cancelToken: options?.cancelToken },
) )
.then(cleanResult); .then(unwrap);
export const apiGetNodeComments = ({ export const apiGetNodeComments = ({
id, id,
@ -121,31 +121,31 @@ export const apiGetNodeComments = ({
.get<ApiGetNodeCommentsResponse>(API.NODES.COMMENT(id), { .get<ApiGetNodeCommentsResponse>(API.NODES.COMMENT(id), {
params: { take, skip }, params: { take, skip },
}) })
.then(cleanResult); .then(unwrap);
export const apiGetNodeRelated = ({ id }: ApiGetNodeRelatedRequest) => export const apiGetNodeRelated = ({ id }: ApiGetNodeRelatedRequest) =>
api.get<ApiGetNodeRelatedResult>(API.NODES.RELATED(id)).then(cleanResult); api.get<ApiGetNodeRelatedResult>(API.NODES.RELATED(id)).then(unwrap);
export const apiPostNodeTags = ({ id, tags }: ApiPostNodeTagsRequest) => export const apiPostNodeTags = ({ id, tags }: ApiPostNodeTagsRequest) =>
api api
.post<ApiPostNodeTagsResult>(API.NODES.UPDATE_TAGS(id), { tags }) .post<ApiPostNodeTagsResult>(API.NODES.UPDATE_TAGS(id), { tags })
.then(cleanResult); .then(unwrap);
export const apiDeleteNodeTag = ({ id, tagId }: ApiDeleteNodeTagsRequest) => export const apiDeleteNodeTag = ({ id, tagId }: ApiDeleteNodeTagsRequest) =>
api api
.delete<ApiDeleteNodeTagsResult>(API.NODES.DELETE_TAG(id, tagId)) .delete<ApiDeleteNodeTagsResult>(API.NODES.DELETE_TAG(id, tagId))
.then(cleanResult); .then(unwrap);
export const apiPostNodeLike = ({ id }: ApiPostNodeLikeRequest) => export const apiPostNodeLike = ({ id }: ApiPostNodeLikeRequest) =>
api.post<ApiPostNodeLikeResult>(API.NODES.LIKE(id)).then(cleanResult); api.post<ApiPostNodeLikeResult>(API.NODES.LIKE(id)).then(unwrap);
export const apiPostNodeHeroic = ({ id }: ApiPostNodeHeroicRequest) => export const apiPostNodeHeroic = ({ id }: ApiPostNodeHeroicRequest) =>
api.post<ApiPostNodeHeroicResponse>(API.NODES.HEROIC(id)).then(cleanResult); api.post<ApiPostNodeHeroicResponse>(API.NODES.HEROIC(id)).then(unwrap);
export const apiLockNode = ({ id, is_locked }: ApiLockNodeRequest) => export const apiLockNode = ({ id, is_locked }: ApiLockNodeRequest) =>
api api
.delete<ApiLockNodeResult>(API.NODES.DELETE(id), { params: { is_locked } }) .delete<ApiLockNodeResult>(API.NODES.DELETE(id), { params: { is_locked } })
.then(cleanResult); .then(unwrap);
export const apiLockComment = ({ export const apiLockComment = ({
id, id,
@ -158,4 +158,4 @@ export const apiLockComment = ({
is_locked: isLocked, is_locked: isLocked,
}, },
}) })
.then(cleanResult); .then(unwrap);

View file

@ -6,26 +6,26 @@ import {
ApiUpdateNoteRequest, ApiUpdateNoteRequest,
} from '~/api/notes/types'; } from '~/api/notes/types';
import { URLS } from '~/constants/urls'; import { URLS } from '~/constants/urls';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
export const apiListNotes = ({ limit, offset, search }: ApiListNotesRequest) => export const apiListNotes = ({ limit, offset, search }: ApiListNotesRequest) =>
api api
.get<ApiGetNotesResponse>(URLS.NOTES, { params: { limit, offset, search } }) .get<ApiGetNotesResponse>(URLS.NOTES, { params: { limit, offset, search } })
.then(cleanResult); .then(unwrap);
export const apiCreateNote = ({ text }: ApiCreateNoteRequest) => export const apiCreateNote = ({ text }: ApiCreateNoteRequest) =>
api api
.post<ApiUpdateNoteResponse>(URLS.NOTES, { .post<ApiUpdateNoteResponse>(URLS.NOTES, {
text, text,
}) })
.then(cleanResult); .then(unwrap);
export const apiDeleteNote = (id: number) => export const apiDeleteNote = (id: number) =>
api.delete(URLS.NOTE(id)).then(cleanResult); api.delete(URLS.NOTE(id)).then(unwrap);
export const apiUpdateNote = ({ id, text }: ApiUpdateNoteRequest) => export const apiUpdateNote = ({ id, text }: ApiUpdateNoteRequest) =>
api api
.put<ApiUpdateNoteResponse>(URLS.NOTE(id), { .put<ApiUpdateNoteResponse>(URLS.NOTE(id), {
content: text, content: text,
}) })
.then(cleanResult); .then(unwrap);

View file

@ -1,6 +1,6 @@
import { API } from '~/constants/api'; import { API } from '~/constants/api';
import { NotificationSettings } from '~/types/notifications'; import { NotificationSettings } from '~/types/notifications';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
import { import {
notificationSettingsFromRequest, notificationSettingsFromRequest,
notificationSettingsToRequest, notificationSettingsToRequest,
@ -15,13 +15,11 @@ import {
export const apiGetNotificationSettings = (): Promise<NotificationSettings> => export const apiGetNotificationSettings = (): Promise<NotificationSettings> =>
api api
.get<ApiGetNotificationSettingsResponse>(API.NOTIFICATIONS.SETTINGS) .get<ApiGetNotificationSettingsResponse>(API.NOTIFICATIONS.SETTINGS)
.then(cleanResult) .then(unwrap)
.then(notificationSettingsFromRequest); .then(notificationSettingsFromRequest);
export const apiGetNotifications = () => export const apiGetNotifications = () =>
api api.get<ApiGetNotificationsResponse>(API.NOTIFICATIONS.LIST).then(unwrap);
.get<ApiGetNotificationsResponse>(API.NOTIFICATIONS.LIST)
.then(cleanResult);
export const apiUpdateNotificationSettings = ( export const apiUpdateNotificationSettings = (
settings: Partial<NotificationSettings>, settings: Partial<NotificationSettings>,
@ -31,5 +29,5 @@ export const apiUpdateNotificationSettings = (
API.NOTIFICATIONS.SETTINGS, API.NOTIFICATIONS.SETTINGS,
notificationSettingsToRequest(settings), notificationSettingsToRequest(settings),
) )
.then(cleanResult) .then(unwrap)
.then(notificationSettingsFromRequest); .then(notificationSettingsFromRequest);

View file

@ -5,14 +5,25 @@ import {
ApiGetTagSuggestionsRequest, ApiGetTagSuggestionsRequest,
ApiGetTagSuggestionsResult, ApiGetTagSuggestionsResult,
} from '~/types/tags'; } from '~/types/tags';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
export const apiGetNodesOfTag = ({ tag, offset, limit }: ApiGetNodesOfTagRequest) => export const apiGetNodesOfTag = ({
tag,
offset,
limit,
}: ApiGetNodesOfTagRequest) =>
api api
.get<ApiGetNodesOfTagResult>(API.TAG.NODES, { params: { name: tag, offset, limit } }) .get<ApiGetNodesOfTagResult>(API.TAG.NODES, {
.then(cleanResult); params: { name: tag, offset, limit },
})
.then(unwrap);
export const apiGetTagSuggestions = ({ search, exclude }: ApiGetTagSuggestionsRequest) => export const apiGetTagSuggestions = ({
search,
exclude,
}: ApiGetTagSuggestionsRequest) =>
api api
.get<ApiGetTagSuggestionsResult>(API.TAG.AUTOCOMPLETE, { params: { search, exclude } }) .get<ApiGetTagSuggestionsResult>(API.TAG.AUTOCOMPLETE, {
.then(cleanResult); params: { search, exclude },
})
.then(unwrap);

View file

@ -1,7 +1,7 @@
import { ApiUploadFileRequest, ApiUploadFIleResult } from '~/api/uploads/types'; import { ApiUploadFileRequest, ApiUploadFIleResult } from '~/api/uploads/types';
import { API } from '~/constants/api'; import { API } from '~/constants/api';
import { UploadTarget, UploadType } from '~/constants/uploads'; import { UploadTarget, UploadType } from '~/constants/uploads';
import { api, cleanResult } from '~/utils/api'; import { api, unwrap } from '~/utils/api';
export const apiUploadFile = ({ export const apiUploadFile = ({
file, file,
@ -16,5 +16,5 @@ export const apiUploadFile = ({
.post<ApiUploadFIleResult>(API.USER.UPLOAD(target, type), data, { .post<ApiUploadFIleResult>(API.USER.UPLOAD(target, type), data, {
onUploadProgress: onProgress, onUploadProgress: onProgress,
}) })
.then(cleanResult); .then(unwrap);
}; };

View file

@ -9,7 +9,7 @@ export const api = axios.create({
}); });
// Pass token to axios // Pass token to axios
api.interceptors.request.use(options => { api.interceptors.request.use((options) => {
const token = getMOBXStore().auth.token; const token = getMOBXStore().auth.token;
if (!token) { if (!token) {
@ -20,15 +20,21 @@ api.interceptors.request.use(options => {
}); });
// Logout on 401 // Logout on 401
api.interceptors.response.use(undefined, (error: AxiosError<{ error: string }>) => { api.interceptors.response.use(
undefined,
(error: AxiosError<{ error: string }>) => {
if (error.response?.status === HTTP_RESPONSES.UNAUTHORIZED) { if (error.response?.status === HTTP_RESPONSES.UNAUTHORIZED) {
getMOBXStore().auth.logout(); getMOBXStore().auth.logout();
} }
error.message = error?.response?.data?.error || error?.response?.statusText || error.message; error.message =
error?.response?.data?.error ||
error?.response?.statusText ||
error.message;
throw error; throw error;
}); },
);
export const HTTP_RESPONSES = { export const HTTP_RESPONSES = {
SUCCESS: 200, SUCCESS: 200,
@ -38,6 +44,7 @@ export const HTTP_RESPONSES = {
UNAUTHORIZED: 401, UNAUTHORIZED: 401,
NOT_FOUND: 404, NOT_FOUND: 404,
TOO_MANY_REQUESTS: 429, TOO_MANY_REQUESTS: 429,
}; } as const;
export const cleanResult = <T extends any>(response: AxiosResponse<T>): T => response?.data; export const unwrap = <T extends any>(response: AxiosResponse<T>): T =>
response?.data;