@seayoo-web/gamer-api
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

Gamer Api Agent

页面初始化

import { NetRequest } from "@seayoo-web/request";
import { AuthToken, EventApi, ClubApi, CommunityApi } from "@seayoo-web/gamer-api";
import { captureException } from "@sentry/vue";
import { GamerWebAuth } from "@seayoo-web/login";

const authToken = new AuthToken(SY_GAMER_API, NetRequest);
const eventApi = new EventApi(authToken, SY_EVENT_ID);
const clubApi = new ClubApi(authToken);
const communityApi = new CommunityApi(authToken);
const loginSDK = new GamerWebAuth(autoToken, {
  anonymous: false,
  hidePasswordLogin: false,
  // 更多配置 @seayoo-web/login
});

// 调整请求配置
authToken.req.setConfig({
  messageHandler(_, message) {
    toast(message);
  },
  errorHandler({ status, rawError, sentryError, sentryTags, sentryExtra }) {
    if (status === 401) {
      // 提示或直接登录
      // loginSDK.login()
      return;
    }
    // 意外错误进行上报
    if (rawError) {
      captureException(sentryError, {
        extra: sentryExtra,
        tags: sentryTags,
      });
    }
  },
});

// 导出供其他功能使用
export { eventApi, clubApi, communityApi, loginSDK };

小程序初始化

import { NetRequest } from "@seayoo-web/request/wx";
import { AuthToken, EventApi, ClubApi, WeixinApi } from "@seayoo-web/gamer-api";
import { GamerWeixinAuth } from "@seayoo-web/login";

const authToken = new AuthToken(SY_GAMER_API, NetRequest);
const eventApi = new EventApi(authToken, SY_EVENT_ID);
const clubApi = new ClubApi(authToken);
const communityApi = new CommunityApi(authToken);
const weixinApi = new WeixinApi(authToken, SY_APP_ID);
const loginSDK = new GamerWeixinAuth(authToken, weixinApi);

// 调整请求配置
authToken.req.setConfig({
  messageHandler(_, message) {
    toast(message);
  },
  errorHandler({ status, rawError, sentryError, sentryTags, sentryExtra }) {
    if (status === 401) {
      // 提示或直接登录
      if(loginSDK.hasLoginToken) {
         loginSDK.login()
      } else {
         // 跳转到用户手机号授权页面
      }
      return;
    }
    // 意外错误进行上报
    if (rawError) {
      captureException(sentryError, {
        extra: sentryExtra,
        tags: sentryTags,
      });
    }
  },
});

// 导出供其他功能使用
export { eventApi, clubApi, communityApi, weixinApi, loginSDK };

Readme

Keywords

none

Package Sidebar

Install

npm i @seayoo-web/gamer-api

Weekly Downloads

287

Version

2.1.0

License

MIT

Unpacked Size

199 kB

Total Files

63

Last publish

Collaborators

  • zjcn5205
  • niboac
  • zhengqiangli
  • celixld