test
This commit is contained in:
4
src/shared/@types/global.d.ts
vendored
4
src/shared/@types/global.d.ts
vendored
@@ -1,3 +1,4 @@
|
||||
import { LoginResponse } from '@/entities/user/model/types';
|
||||
import type { DefaultEvents, EventEmitter } from '@webview-bridge/web';
|
||||
|
||||
export {};
|
||||
@@ -41,5 +42,6 @@ declare global {
|
||||
ReactNativeWebView: {
|
||||
postMessage: (data: string) => void;
|
||||
};
|
||||
saveToken: (token: LoginResponse) => void;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,16 @@ import { StorageKeys } from '@/shared/constants/local-storage';
|
||||
import { checkIsAxiosError, getLocalStorage } from '@/shared/lib';
|
||||
import { finalizeConfig, extractAccessToken, extractRequestId } from './utils';
|
||||
import { HEADER_USER_AGENT } from '@/shared/constants/url';
|
||||
import { useAppBridge } from '@/hooks';
|
||||
import { useUserInfo } from '@/entities/user/lib/use-user-info';
|
||||
|
||||
/*
|
||||
const {
|
||||
isNativeEnvironment,
|
||||
requestRefreshToken
|
||||
} = useAppBridge();
|
||||
const { updateUserData } = useUserInfo();
|
||||
*/
|
||||
const onRequestFulfilled = (config: InternalAxiosRequestConfig) => {
|
||||
config.headers['Content-Type'] = 'application/json;charset=UTF-8';
|
||||
config.headers['X-User-Agent'] = HEADER_USER_AGENT;
|
||||
@@ -26,6 +35,7 @@ const onRequestFulfilled = (config: InternalAxiosRequestConfig) => {
|
||||
|
||||
const onRequestRejected = (error: any) => {
|
||||
const { method, url, params, data, headers } = error.config;
|
||||
/*
|
||||
Sentry.setContext('API Request Detail', {
|
||||
method,
|
||||
url,
|
||||
@@ -33,7 +43,7 @@ const onRequestRejected = (error: any) => {
|
||||
data,
|
||||
headers,
|
||||
});
|
||||
|
||||
*/
|
||||
return Promise.reject(error);
|
||||
};
|
||||
|
||||
@@ -47,7 +57,30 @@ const onResponseFulfilled = (response: AxiosResponse) => {
|
||||
};
|
||||
|
||||
const onResponseRejected = (error: AxiosError) => {
|
||||
if (error?.response) {
|
||||
/*
|
||||
const {
|
||||
isNativeEnvironment,
|
||||
requestRefreshToken
|
||||
} = useAppBridge();
|
||||
const { updateUserData } = useUserInfo();
|
||||
*/
|
||||
console.log('onResponseRejected --> ', error)
|
||||
if(error?.status === 401){
|
||||
/*
|
||||
if(isNativeEnvironment){
|
||||
requestRefreshToken().then((token) => {
|
||||
updateUserData(token);
|
||||
});
|
||||
}
|
||||
else{
|
||||
requestRefreshToken().then((token) => {
|
||||
updateUserData(token);
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
/*
|
||||
else if (error?.response) {
|
||||
const { data, status } = error.response;
|
||||
extractRequestId(error?.response);
|
||||
Sentry.setContext('API Response Detail', {
|
||||
@@ -55,6 +88,7 @@ const onResponseRejected = (error: AxiosError) => {
|
||||
data,
|
||||
});
|
||||
}
|
||||
*/
|
||||
return new Promise((_resolve, reject) => {
|
||||
if (checkIsAxiosError(error)) {
|
||||
// iOS의 경우 window에서 unload event가 일어날때 네트워크 에러가 발생하곤 해서 이런 케이스를 방지하기 위해 지연시킴
|
||||
|
||||
@@ -23,6 +23,7 @@ export const extractRequestId = (response: AxiosResponse): void => {
|
||||
const requestIdHeader = response?.headers?.['x-request-id'];
|
||||
if (requestIdHeader) {
|
||||
const requestId = requestIdHeader.replaceAll(', *', '');
|
||||
console.log('requestId --> ', requestId);
|
||||
setLocalStorage(StorageKeys.RequestId, requestId);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user