|
|
|
@ -2,6 +2,13 @@ import { isFunction } from '../is.js' |
|
|
|
import env from '@/env/index.js' |
|
|
|
const urlEnv = env === 'production' ? '' : `-${env}` |
|
|
|
const uploadUrl = `https://api-ops-yyt${urlEnv}.qniao.cn/cloud-print-user-center/utils/uploadImage` |
|
|
|
|
|
|
|
/** |
|
|
|
* 定义的一个thenable对象 |
|
|
|
*/ |
|
|
|
class ErrorPromise { |
|
|
|
then() {} |
|
|
|
} |
|
|
|
export default class Http { |
|
|
|
constructor(config = {}, { reqInterceptor, resInterceptor, transformConfig } = {}) { |
|
|
|
this.baseUrl = config.baseUrl |
|
|
|
@ -55,6 +62,8 @@ export default class Http { |
|
|
|
let data = resInterceptor(res, opt) |
|
|
|
if (!data) { |
|
|
|
console.log('报错的请求参数:', conf) |
|
|
|
reject(res) |
|
|
|
return |
|
|
|
} |
|
|
|
// 服务器错误也会用then抛出,需要自己判断data==null
|
|
|
|
resolve(data) |
|
|
|
@ -69,6 +78,7 @@ export default class Http { |
|
|
|
}).catch((err) => { |
|
|
|
// 吃掉请求产生的异常 后期可以记录
|
|
|
|
console.error('native response error', err) |
|
|
|
return new ErrorPromise() |
|
|
|
}) |
|
|
|
} |
|
|
|
// config:{}
|
|
|
|
|