@thepassle/app-tools 0.8.9 → 0.9.0
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/api/index.js +10 -3
- package/package.json +1 -1
- package/router/index.js +5 -0
package/api/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { createLogger } from '../utils/log.js';
|
|
2
2
|
const log = createLogger('api');
|
|
3
3
|
|
|
4
|
+
class StatusError extends Error {
|
|
5
|
+
constructor(response) {
|
|
6
|
+
super(response.statusText);
|
|
7
|
+
this.response = response;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
function handleStatus(response) {
|
|
5
12
|
if (!response.ok) {
|
|
6
|
-
log('Response not ok', response
|
|
7
|
-
throw new
|
|
13
|
+
log('Response not ok', response);
|
|
14
|
+
throw new StatusError(response);
|
|
8
15
|
}
|
|
9
16
|
return response;
|
|
10
17
|
}
|
|
@@ -137,7 +144,7 @@ export class Api {
|
|
|
137
144
|
/** [PLUGINS - HANDLEERROR] */
|
|
138
145
|
.catch(async e => {
|
|
139
146
|
log(`Fetch failed ${method} ${url}`, e);
|
|
140
|
-
const shouldThrow = (await Promise.all(plugins.map(({handleError}) => handleError?.(e) ??
|
|
147
|
+
const shouldThrow = plugins.length === 0 || (await Promise.all(plugins.map(({ handleError }) => handleError?.(e) ?? true))).every(_ => !!_);
|
|
141
148
|
if(shouldThrow) throw e;
|
|
142
149
|
});
|
|
143
150
|
}
|
package/package.json
CHANGED
package/router/index.js
CHANGED
|
@@ -57,6 +57,11 @@ export class Router extends EventTarget {
|
|
|
57
57
|
window.addEventListener('click', this._onAnchorClick);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
uninstall() {
|
|
61
|
+
window.removeEventListener('popstate', this._onPopState);
|
|
62
|
+
window.removeEventListener('click', this._onAnchorClick);
|
|
63
|
+
}
|
|
64
|
+
|
|
60
65
|
get url() {
|
|
61
66
|
return new URL(window.location.href);
|
|
62
67
|
}
|