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

Method request

wxapp/colorful.js:207–225  ·  view source on GitHub ↗
(apiPath, { method = "GET", data, params, auth = true } = {})

Source from the content-addressed store, hash-verified

205 }
206
207 async request(apiPath, { method = "GET", data, params, auth = true } = {}) {
208 const options = {
209 method,
210 url: new URL(apiPath, API_BASE).toString(),
211 params,
212 headers: this.signedHeaders({}, auth),
213 timeout: 15000,
214 validateStatus: () => true,
215 };
216 if (data !== undefined) options.data = data;
217 const { data: result, status, headers } = await axios.request(options);
218 if (headers?.["access-token"]) this.token = headers["access-token"];
219 if (headers?.["x-access-token"]) this.refreshToken = headers["x-access-token"];
220 if (status === 401 || status === 403) throw new Error(`HTTP ${status}: ${result?.Message || JSON.stringify(result)}`);
221 if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`);
222 if (!isSuccess(result)) throw new Error(`${result?.Code ?? ""} ${result?.Message || result?.msg || JSON.stringify(result)}`.trim());
223 if (this.token) this.saveCachedToken();
224 return result;
225 }
226
227 async getLoginCode() {
228 if (!process.env.wx_auth) throw new Error("缺少 wx_auth,无法从 wx_server 获取 code");

Callers 6

loginByWxCodeMethod · 0.95
checkTokenMethod · 0.95
signInV2Method · 0.95
getSignInfoMethod · 0.95
getUserInfoMethod · 0.95
getNoticeFunction · 0.45

Calls 3

signedHeadersMethod · 0.95
saveCachedTokenMethod · 0.95
isSuccessFunction · 0.70

Tested by

no test coverage detected