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

Method request

wxapp/aiguoyue.js:154–175  ·  view source on GitHub ↗
({ method = "GET", apiPath, query = {}, data = {}, skipToken = false })

Source from the content-addressed store, hash-verified

152 }
153
154 async request({ method = "GET", apiPath, query = {}, data = {}, skipToken = false }) {
155 const oldToken = this.token;
156 if (skipToken) this.token = {};
157 const options = {
158 method,
159 url: this.buildUrl(apiPath, query),
160 headers: this.getHeaders(method === "POST" ? { "Content-Type": "application/json" } : {}),
161 timeout: 15000,
162 validateStatus: () => true,
163 };
164 if (method !== "GET") options.data = data;
165 if (skipToken) this.token = oldToken;
166
167 const { status, data: result } = await axios.request(options);
168 if (status !== 200) throw new Error(`HTTP ${status}: ${typeof result === "string" ? result.slice(0, 200) : JSON.stringify(result)}`);
169 if (!result || result.code !== 0) {
170 const err = new Error(result?.msg || result?.message || JSON.stringify(result));
171 err.code = result?.code;
172 throw err;
173 }
174 return result.data;
175 }
176
177 async getWxCode() {
178 const wxServerUrl = process.env.wx_server_url;

Callers 5

loginByWxCodeMethod · 0.95
getPointsMethod · 0.95
getCheckinInfoMethod · 0.95
getActivityInfoMethod · 0.95
doCheckinMethod · 0.95

Calls 2

buildUrlMethod · 0.95
getHeadersMethod · 0.95

Tested by

no test coverage detected