hamzus-ui 0.0.227 → 0.0.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/request.js +15 -12
package/package.json
CHANGED
package/src/utils/request.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { getCookie } from "./clientCookie";
|
|
2
2
|
import { config } from "./hamzus.config.js";
|
|
3
3
|
|
|
4
|
+
let on401Promise = null; // promesse partagée pendant que on401 tourne
|
|
5
|
+
|
|
4
6
|
export function sendRequest(request) {
|
|
5
7
|
return new Promise((resolve, reject) => {
|
|
6
8
|
request = {
|
|
@@ -39,23 +41,24 @@ export function sendRequest(request) {
|
|
|
39
41
|
|
|
40
42
|
xhr.onload = function () {
|
|
41
43
|
if (xhr.status === 200) {
|
|
42
|
-
|
|
43
|
-
resolve(response)
|
|
44
|
+
resolve(JSON.parse(xhr.responseText))
|
|
44
45
|
} else if (xhr.status === 400 || xhr.status === 409) {
|
|
45
|
-
|
|
46
|
-
resolve(response)
|
|
46
|
+
resolve(JSON.parse(xhr.responseText))
|
|
47
47
|
} else if (xhr.status === 401) {
|
|
48
|
-
if (config.on401
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
result instanceof Promise
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
if (!isRetry && config.on401 != null) {
|
|
49
|
+
if (!on401Promise) {
|
|
50
|
+
// Personne d'autre ne tourne on401, on le lance
|
|
51
|
+
const result = config.on401();
|
|
52
|
+
on401Promise = (result instanceof Promise ? result : Promise.resolve())
|
|
53
|
+
.finally(() => { on401Promise = null; });
|
|
54
|
+
}
|
|
55
|
+
if (config.replayAfter401 === true) {
|
|
56
|
+
// On attend la fin du on401 (le nôtre ou celui d'un autre)
|
|
57
|
+
on401Promise.then(() => executeRequest(true));
|
|
55
58
|
return;
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
|
-
resolve(false)
|
|
61
|
+
resolve(false);
|
|
59
62
|
}
|
|
60
63
|
};
|
|
61
64
|
|