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

Method request

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

Source from the content-addressed store, hash-verified

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

Callers 4

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

Calls 2

buildUrlMethod · 0.95
getHeadersMethod · 0.95

Tested by

no test coverage detected