MCPcopy Create free account
hub / github.com/apitable/apitable / handleResponse

Function handleResponse

packages/datasheet/src/modules/api/utils/init_axios.tsx:43–175  ·  view source on GitHub ↗
(response, headers: any | undefined, url: string | undefined)

Source from the content-addressed store, hash-verified

41}
42
43export function handleResponse<T>(response, headers: any | undefined, url: string | undefined) {
44 const { success, code, message = 'Error' } = response;
45
46 // const IGNORE_PATH_REG = /^\/(share|template|notify|embed)/;
47 // if (success && data && url?.startsWith('/nest/v1/') && !IGNORE_PATH_REG.test(location.pathname)) {
48 // const state = store.getState();
49 // const activeSpaceId = Selectors.activeSpaceId(state);
50 // // @ts-ignore
51 // const spaceId = data.datasheet?.spaceId || data.mirror?.spaceId || data.dashboard?.spaceId || data.form?.spaceId;
52 // if (spaceId && spaceId !== activeSpaceId) {
53 // axios.defaults.headers.common['X-Space-Id'] = spaceId;
54 // // @ts-ignore
55 // store.dispatch(StoreActions.getUserMe({ spaceId }));
56 // }
57 // }
58 //
59 // if (!success && String(code).startsWith('5')) {
60 // Sentry.captureMessage(message, {
61 // extra: {
62 // headers: headers,
63 // },
64 // });
65 // }
66 // if (success || hasUrlIgnore(url)) {
67 // return response;
68 // }
69 if (success) {
70 return {
71 data: response,
72 };
73 }
74
75 try {
76 apiErrorManager.handleError(code);
77 } catch (e) {
78 throw new Error(message);
79 }
80
81 switch (code) {
82 case StatusCode.UN_AUTHORIZED: {
83 if (window.location.pathname !== '/login') {
84 Modal.error({
85 title: t(Strings.login_status_expired_title),
86 content: t(Strings.login_status_expired_content),
87 okText: t(Strings.login_status_expired_button),
88 onOk: () => {
89 const isDingding = isDingtalkFunc();
90 if (isDingding) {
91 window.location.href = `/user/dingtalk/social_login${window.location.search}`;
92 return;
93 }
94 const IS_EMBED_LINK_REG = /^\/embed/;
95 const reference = !IS_EMBED_LINK_REG.test(location.pathname)
96 ? new URLSearchParams(window.location.search).get('reference')?.toString()
97 : window.location.href;
98 store.dispatch(StoreActions.setUserMe(null));
99 store.dispatch(StoreActions.setIsLogin(false));
100 Router.redirect(Navigation.LOGIN, { query: { reference } });

Callers 1

initAxiosFunction · 0.85

Calls 9

tFunction · 0.90
isDingtalkFuncFunction · 0.85
redirectMethod · 0.80
errorMethod · 0.65
getMethod · 0.65
handleErrorMethod · 0.45
testMethod · 0.45
toStringMethod · 0.45
dispatchMethod · 0.45

Tested by

no test coverage detected