/*
 * @Author: wjc
 * @Date: 2023-11-17 11:46:48
 * @LastEditors: LiZhiWei
 * @LastEditTime: 2026-01-09 15:40:43
 * @Description:
 */
import type { FetchContext, FetchResponse } from 'ofetch'
import { apiBase } from '~/constants'
import Request from './request'
import { checkStatus } from './checkStatus'

const http = new Request({
  baseURL: `${apiBase}`,
  interceptor: {
    // 响应错误拦截
    onResponseError({ response }: FetchContext & { response: FetchResponse<any> }) {
      if (response?.status) {
        checkStatus(response?.status, response._data?.message || '服务不可用，请稍候再试')
      }
    },
  },
})

export { http }
