|
@@ -1,5 +1,6 @@
|
|
|
(function () {
|
|
(function () {
|
|
|
const TOKEN_KEY = 'pouchlab.token.v1';
|
|
const TOKEN_KEY = 'pouchlab.token.v1';
|
|
|
|
|
+ const bindWaiters = [];
|
|
|
|
|
|
|
|
function langHeader() {
|
|
function langHeader() {
|
|
|
const lang = window.PL && window.PL.i18n ? window.PL.i18n.getLang() : 'zh';
|
|
const lang = window.PL && window.PL.i18n ? window.PL.i18n.getLang() : 'zh';
|
|
@@ -42,8 +43,16 @@
|
|
|
document.dispatchEvent(new CustomEvent('pl:auth-expired'));
|
|
document.dispatchEvent(new CustomEvent('pl:auth-expired'));
|
|
|
}
|
|
}
|
|
|
return res.json().catch(function () { return {}; }).then(function (data) {
|
|
return res.json().catch(function () { return {}; }).then(function (data) {
|
|
|
|
|
+ if (res.status === 403 && data.detail && data.detail.code === 'bind-email') {
|
|
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
|
|
+ bindWaiters.push(function () { request(method, path, body, opts).then(resolve, reject); });
|
|
|
|
|
+ document.dispatchEvent(new CustomEvent('pl:bind-email-required',
|
|
|
|
|
+ { detail: { message: data.detail.message } }));
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
if (!res.ok) {
|
|
if (!res.ok) {
|
|
|
- const err = new Error(data.detail || tr('请求失败(' + res.status + ')'));
|
|
|
|
|
|
|
+ const msg = data.detail && data.detail.message ? data.detail.message : data.detail;
|
|
|
|
|
+ const err = new Error(msg || tr('请求失败(' + res.status + ')'));
|
|
|
err.status = res.status;
|
|
err.status = res.status;
|
|
|
throw err;
|
|
throw err;
|
|
|
}
|
|
}
|
|
@@ -119,6 +128,10 @@
|
|
|
svgToPng: svgToPng,
|
|
svgToPng: svgToPng,
|
|
|
get: function (p, o) { return request('GET', p, undefined, o); },
|
|
get: function (p, o) { return request('GET', p, undefined, o); },
|
|
|
post: function (p, b, o) { return request('POST', p, b, o); },
|
|
post: function (p, b, o) { return request('POST', p, b, o); },
|
|
|
- patch: function (p, b, o) { return request('PATCH', p, b, o); }
|
|
|
|
|
|
|
+ patch: function (p, b, o) { return request('PATCH', p, b, o); },
|
|
|
|
|
+ flushBind: function () {
|
|
|
|
|
+ const list = bindWaiters.splice(0);
|
|
|
|
|
+ list.forEach(function (run) { try { run(); } catch (e) {} });
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
})();
|
|
})();
|