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

Method request

wxapp/niuniuduanju.js:139–159  ·  view source on GitHub ↗
({ method = "GET", apiPath, params = {}, data = {}, token = true, json = false })

Source from the content-addressed store, hash-verified

137 }
138
139 async request({ method = "GET", apiPath, params = {}, data = {}, token = true, json = false }) {
140 const options = {
141 method,
142 url: `${API_BASE}${apiPath.startsWith("/") ? apiPath : `/${apiPath}`}`,
143 headers: this.getHeaders(json ? { "content-type": "application/json" } : {}),
144 timeout: 15000,
145 validateStatus: () => true,
146 };
147 if (!token) delete options.headers.token;
148 if (method === "GET") options.params = params;
149 else options.data = data;
150
151 const { status, data: result } = await axios.request(options);
152 if (status !== 200) throw new Error(`HTTP ${status}: ${typeof result === "string" ? result.slice(0, 200) : JSON.stringify(result)}`);
153 if (!result || result.code !== 0) {
154 const err = new Error(result?.msg || result?.message || JSON.stringify(result));
155 err.code = result?.code;
156 throw err;
157 }
158 return result;
159 }
160
161 async getWxCode() {
162 const wxServerUrl = process.env.wx_server_url;

Callers 15

loginByWxCodeMethod · 0.95
checkTokenMethod · 0.95
getPointsMethod · 0.95
getSignStatusMethod · 0.95
signInMethod · 0.95
claimDailyTaskMethod · 0.95
completeEatGoldTasksMethod · 0.95
updateUserWatchCountMethod · 0.95
getUserInfoMethod · 0.95

Calls 1

getHeadersMethod · 0.95

Tested by

no test coverage detected