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

Method request

wxapp/mengxiangjia.js:135–154  ·  view source on GitHub ↗
({ method = "GET", apiPath, data = {}, params = {}, needToken = true })

Source from the content-addressed store, hash-verified

133 }
134
135 async request({ method = "GET", apiPath, data = {}, params = {}, needToken = true }) {
136 const options = {
137 method,
138 url: `${API_BASE}${apiPath}`,
139 headers: this.headers(needToken),
140 timeout: 15000,
141 validateStatus: () => true,
142 };
143 if (method.toUpperCase() === "GET") options.params = params;
144 else options.data = data;
145
146 const { status, data: result } = await axios.request(options);
147 if (status !== 200) throw new Error(`HTTP ${status}: ${typeof result === "string" ? result.slice(0, 200) : JSON.stringify(result)}`);
148 if (result && Object.prototype.hasOwnProperty.call(result, "error") && Number(result.error) !== 0) {
149 const err = new Error(result.errorMsg || result.error_msg || result.message || JSON.stringify(result));
150 err.code = result.error;
151 throw err;
152 }
153 return result;
154 }
155
156 async getWxCode() {
157 const wxServerUrl = process.env.wx_server_url;

Callers 5

loginByWxCodeMethod · 0.95
getSignConfigMethod · 0.95
getTodaySignItemMethod · 0.95
getPointsInfoMethod · 0.95
signInMethod · 0.95

Calls 2

headersMethod · 0.95
callMethod · 0.80

Tested by

no test coverage detected