MCPcopy Index your code
hub / github.com/smallfawn/QLScriptPublic / request

Method request

wxapp/fafa.js:165–187  ·  view source on GitHub ↗
({ method = "POST", apiPath, params = {}, data = {}, skipToken = false })

Source from the content-addressed store, hash-verified

163 }
164
165 async request({ method = "POST", apiPath, params = {}, data = {}, skipToken = false }) {
166 const upperMethod = method.toUpperCase();
167 const options = {
168 method: upperMethod,
169 url: `${API_BASE}${apiPath}`,
170 headers: this.headers(upperMethod === "POST" ? { "Content-Type": "application/json" } : {}),
171 timeout: 20000,
172 validateStatus: () => true,
173 };
174 if (upperMethod === "GET") options.params = params;
175 else options.data = data;
176 if (skipToken) delete options.headers.Authorization;
177
178 const res = await axios.request(options);
179 if (res.status !== 200) throw new Error(`HTTP ${res.status}: ${JSON.stringify(res.data)}`);
180 const result = res.data;
181 if (result && typeof result === "object" && result.error !== undefined && Number(result.error) !== 0) {
182 const err = new Error(result.errorMsg || result.message || result.msg || JSON.stringify(result));
183 err.code = result.error;
184 throw err;
185 }
186 return result?.data ?? result;
187 }
188
189 async getLoginCode() {
190 const { data } = await wechat.getCode(this.account);

Callers 5

loginByWxCodeMethod · 0.95
getUserInfoMethod · 0.95
getPointsInfoMethod · 0.95
getSignListMethod · 0.95
doSignMethod · 0.95

Calls 1

headersMethod · 0.95

Tested by

no test coverage detected