统一前端错误读取和调试日志
This commit is contained in:
@@ -2,6 +2,7 @@ import axios, { type AxiosResponse, type InternalAxiosRequestConfig, type AxiosE
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { showToast } from 'vant'
|
||||
import { apiMonitor } from './monitor'
|
||||
import { debugError, debugLog } from '@/shared/utils/debug'
|
||||
|
||||
function showError(message: string) {
|
||||
const isMobile = window.location.pathname.startsWith('/m')
|
||||
@@ -24,7 +25,7 @@ declare module 'axios' {
|
||||
// 开发环境日志记录
|
||||
function logRequest(config: InternalAxiosRequestConfig) {
|
||||
if (import.meta.env.DEV) {
|
||||
console.log(`[API Request] ${config.method?.toUpperCase()} ${config.url}`, {
|
||||
debugLog(`[API Request] ${config.method?.toUpperCase()} ${config.url}`, {
|
||||
params: config.params,
|
||||
data: config.data,
|
||||
headers: config.headers,
|
||||
@@ -38,7 +39,7 @@ function logRequest(config: InternalAxiosRequestConfig) {
|
||||
function logResponse(response: AxiosResponse) {
|
||||
if (import.meta.env.DEV) {
|
||||
const duration = response.config._startTime ? Date.now() - response.config._startTime : 0
|
||||
console.log(
|
||||
debugLog(
|
||||
`[API Response] ${response.config.method?.toUpperCase()} ${response.config.url} (${duration}ms)`,
|
||||
{
|
||||
status: response.status,
|
||||
@@ -63,7 +64,7 @@ function logResponse(response: AxiosResponse) {
|
||||
function logError(error: AxiosError) {
|
||||
if (import.meta.env.DEV) {
|
||||
const duration = error.config?._startTime ? Date.now() - error.config._startTime : 0
|
||||
console.error(
|
||||
debugError(
|
||||
`[API Error] ${error.config?.method?.toUpperCase()} ${error.config?.url} (${duration}ms)`,
|
||||
{
|
||||
status: error.response?.status,
|
||||
|
||||
Reference in New Issue
Block a user