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

Method request

wxapp/kangshifu.js:153–171  ·  view source on GitHub ↗
(baseURL, apiPath, { method = "GET", data, params, auth = true, form = false } = {})

Source from the content-addressed store, hash-verified

151 }
152
153 async request(baseURL, apiPath, { method = "GET", data, params, auth = true, form = false } = {}) {
154 const options = {
155 method,
156 url: new URL(apiPath, baseURL).toString(),
157 params,
158 headers: this.headers(form ? {
159 "Content-Type": "application/x-www-form-urlencoded;",
160 } : {}),
161 timeout: 15000,
162 validateStatus: () => true,
163 };
164 if (!auth) delete options.headers.token;
165 if (data !== undefined) options.data = form ? formBody(data) : data;
166
167 const { data: result, status } = await axios.request(options);
168 if (status !== 200) throw new Error(`HTTP ${status}: ${JSON.stringify(result)}`);
169 if (!isSuccess(result)) throw new Error(`${result?.code ?? ""} ${result?.msg || result?.error || JSON.stringify(result)}`.trim());
170 return result;
171 }
172
173 async getLoginCode() {
174 if (!process.env.wx_auth) throw new Error("缺少 wx_auth,无法从 wx_server 获取 code");

Callers 5

loginByWxCodeMethod · 0.95
getMemberInfoMethod · 0.95
getSignStatusMethod · 0.95
signInMethod · 0.95
getNoticeFunction · 0.45

Calls 3

headersMethod · 0.95
formBodyFunction · 0.70
isSuccessFunction · 0.70

Tested by

no test coverage detected