2
This commit is contained in:
@@ -30,8 +30,19 @@ function buildAuthHeaders(base = {}) {
|
||||
headers["X-Shop-Id"] = claims.shopId;
|
||||
if (claims && claims.userId)
|
||||
headers["X-User-Id"] = claims.userId;
|
||||
} else if (common_config.ENABLE_DEFAULT_USER && common_config.DEFAULT_USER_ID) {
|
||||
if (headers["Authorization"])
|
||||
delete headers["Authorization"];
|
||||
headers["X-User-Id"] = headers["X-User-Id"] || common_config.DEFAULT_USER_ID;
|
||||
if (common_config.SHOP_ID)
|
||||
headers["X-Shop-Id"] = headers["X-Shop-Id"] || common_config.SHOP_ID;
|
||||
}
|
||||
} catch (_) {
|
||||
if (common_config.ENABLE_DEFAULT_USER && common_config.DEFAULT_USER_ID) {
|
||||
headers["X-User-Id"] = headers["X-User-Id"] || common_config.DEFAULT_USER_ID;
|
||||
if (common_config.SHOP_ID)
|
||||
headers["X-Shop-Id"] = headers["X-Shop-Id"] || common_config.SHOP_ID;
|
||||
}
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
@@ -71,7 +82,7 @@ function post(path, body = {}) {
|
||||
const headers = buildAuthHeaders({ "Content-Type": "application/json" });
|
||||
const options = { url: buildUrl(path), method: "POST", data: body, header: headers };
|
||||
const p = String(path || "");
|
||||
if (p.includes("/api/auth/wxmp/login") || p.includes("/api/auth/sms/login") || p.includes("/api/auth/sms/send") || p.includes("/api/auth/password/login") || p.includes("/api/auth/register"))
|
||||
if (p.includes("/api/auth/wxmp/login") || p.includes("/api/auth/sms/login") || p.includes("/api/auth/sms/send") || p.includes("/api/auth/email/login") || p.includes("/api/auth/email/send") || p.includes("/api/auth/password/login") || p.includes("/api/auth/register"))
|
||||
options.__noRetry = true;
|
||||
requestWithFallback(options, common_config.API_BASE_URL_CANDIDATES, 0, resolve, reject);
|
||||
});
|
||||
@@ -106,9 +117,22 @@ function uploadWithFallback(options, candidates, idx, resolve, reject) {
|
||||
return resolve(res.data);
|
||||
}
|
||||
}
|
||||
if (statusCode >= 400 && statusCode < 500) {
|
||||
try {
|
||||
const data = typeof res.data === "string" ? JSON.parse(res.data) : res.data;
|
||||
return resolve(data);
|
||||
} catch (e) {
|
||||
return resolve({ success: false, message: "HTTP " + statusCode });
|
||||
}
|
||||
}
|
||||
if (idx + 1 < candidates.length)
|
||||
return uploadWithFallback(options, candidates, idx + 1, resolve, reject);
|
||||
reject(new Error("HTTP " + statusCode));
|
||||
try {
|
||||
const data = typeof res.data === "string" ? JSON.parse(res.data) : res.data;
|
||||
return resolve(data);
|
||||
} catch (e) {
|
||||
return resolve({ success: false, message: "HTTP " + statusCode });
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
if (idx + 1 < candidates.length)
|
||||
|
||||
Reference in New Issue
Block a user