39 lines
1,005 B
TypeScript
39 lines
1,005 B
TypeScript
import appConfig from '@/configs/app.config'
|
|
import { store } from '@/store'
|
|
import axios from 'axios'
|
|
|
|
const authApiService = axios.create({
|
|
timeout: 10000,
|
|
baseURL: appConfig.baseUrl,
|
|
})
|
|
|
|
authApiService.interceptors.response.use(
|
|
(response) => response,
|
|
async (error) => {
|
|
console.log('Error interceptor')
|
|
console.error(error)
|
|
const { messages } = store.getActions().base
|
|
messages.addError({
|
|
id: crypto.randomUUID(),
|
|
message: error.response?.data?.error?.message ?? error.message ?? 'Bir hata oluştu',
|
|
title: 'Hata!',
|
|
cid: error.response?.headers['x-correlation-id'],
|
|
statusCode: error.response?.status?.toString() ?? error.code,
|
|
})
|
|
|
|
return Promise.reject(error)
|
|
},
|
|
)
|
|
|
|
authApiService.interceptors.request.use(async (config) => {
|
|
const { tenantId } = store.getState().auth
|
|
if (tenantId) {
|
|
config.headers['__tenant'] = tenantId
|
|
} else {
|
|
config.headers.delete('__tenant')
|
|
}
|
|
|
|
return config
|
|
})
|
|
|
|
export default authApiService
|