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

Method request

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

Source from the content-addressed store, hash-verified

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