"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const nprogress_1 = tslib_1.__importDefault(require("nprogress"));
const umi_1 = require("umi");
const WxSnackBar_1 = tslib_1.__importDefault(require("../WxSnackBar"));
/**
 * 请求wxapi
 * @param wxRequest wxRequest方法
 * @param whole 是否返回全部结构，默认只返回data
 */
async function requestWxApi(wxRequest, whole) {
    try {
        const sessionToken = localStorage.getItem('sessionToken') || '';
        nprogress_1.default.start();
        const { data: ret } = await wxRequest(sessionToken);
        nprogress_1.default.done();
        if (ret.code === 0) {
            return whole ? ret : ret.data;
        }
        else {
            WxSnackBar_1.default.error(JSON.stringify(ret.message));
            if (ret.code === 1001 && process.env.NODE_ENV !== 'development') {
                umi_1.history.push('/logout');
            }
            return ret;
        }
    }
    catch (error) {
        console.log(error);
        nprogress_1.default.done();
        throw error;
    }
}
exports.default = requestWxApi;
