import webUiConstants from '@/constants'
import axios from 'axios'
import { redirectToLogin } from '@/lib/auth-redirect'

export const httpClient = axios.create({
  baseURL: webUiConstants.baseUrl+'api',
  withCredentials: true
})

httpClient.interceptors.response.use(
  (response) => response,
  (error) => {
    const status = error?.response?.status
    if (status === 401) {
      redirectToLogin()
    }
    if (import.meta.env.DEV) {
      console.error('HTTP error', error)
    }
    return Promise.reject(error)
  }
)
