MCPcopy Create free account
hub / github.com/smallfawn/QLScriptPublic / request

Method request

wxapp/zbs.js:148–164  ·  view source on GitHub ↗
(apiPath, { method = "GET", data = {}, auth = true } = {})

Source from the content-addressed store, hash-verified

146 }
147
148 async request(apiPath, { method = "GET", data = {}, auth = true } = {}) {
149 const options = {
150 method,
151 url: new URL(apiPath, API_BASE).toString(),
152 headers: this.headers(),
153 timeout: 15000,
154 validateStatus: () => true,
155 };
156 if (!auth) delete options.headers["X-Dts-Token"];
157 if (method.toUpperCase() === "GET") options.params = data;
158 else options.data = data;
159
160 const { data: result, status } = await axios.request(options);
161 if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`);
162 if (Number(result?.errno) !== 0) throw new Error(`${result?.errno ?? ""} ${result?.errmsg || result?.message || JSON.stringify(result)}`.trim());
163 return result;
164 }
165
166 async getLoginCode() {
167 if (!process.env.wx_auth) throw new Error("缺少 wx_auth,无法从 wx_server 获取 code");

Callers 5

loginByWxCodeMethod · 0.95
checkTokenMethod · 0.95
getPointsMethod · 0.95
signInMethod · 0.95
getNoticeFunction · 0.45

Calls 1

headersMethod · 0.95

Tested by

no test coverage detected