@monda/request
v0.0.5
Published
异步请求工具
Maintainers
Readme
安装
npm install -D @monda/request使用
import { createRequest } from "@monda/request"案例
export const http = createRequest(options)
// 添加异常处理拦截器
http.interceptors.response.use(response => response, async error => {
const message = error.message || '服务异常'
const { origin, href } = location
const goto = encodeURIComponent(href)
switch (error?.response?.status) {
case 401: return location.href = `${ origin }/login?goto=${ goto }` // 登陆
case 502: return location.href = `${ origin }/502?goto=${ goto }` // 提示部署
default: location.href = `${ origin }/500?goto=${ goto }&message=${ message }` // 提示错误
}
return Promise.reject(error)
})options
const options = {
baseURL: '',
method: 'get',
responseType: 'json',
headers: { },
timeout: 1000 * 14, // 请求超时限制
delay: 500, // 最低反馈时间
intact: false, // intact=false 时返回 response.result, intact=true 时返回 response
}