Skip to content

Commit

Permalink
fix: 修复 Ajax 错误
Browse files Browse the repository at this point in the history
  • Loading branch information
CaoMeiYouRen committed Jan 24, 2022
1 parent b0fce38 commit b35c895
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/utils/ajax.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import axios, { AxiosResponse, Method } from 'axios'
import axios, { AxiosResponse, Method, AxiosRequestHeaders } from 'axios'
import qs from 'qs'
import debug from 'debug'

const Debugger = debug('push:ajax')

class AjaxConfig {
interface AjaxConfig {
url: string
query?: Record<string, unknown>
data?: Record<string, unknown> | string | Buffer | ArrayBuffer
method?: Method = 'GET'
headers?: Record<string, unknown>
method?: Method
headers?: AxiosRequestHeaders
}

/**
Expand Down Expand Up @@ -51,11 +51,15 @@ export async function ajax(config: AjaxConfig): Promise<AxiosResponse<any>> {
Debugger('response data: %O', response.data)
return response
} catch (error) {
if (error.toJSON) {
console.error(error?.response || error.toJSON())
if (error?.response) {
console.error(error.response)
return error.response
}
console.error(error)
if (error.toJSON) {
console.error(error.toJSON())
} else {
console.error(error)
}
throw error
}
}

0 comments on commit b35c895

Please sign in to comment.