chrome-webstore-upload 3.0.2 → 3.0.3
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/index.js +25 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -13,6 +13,14 @@ const getURI = (id, projection) =>
|
|
|
13
13
|
|
|
14
14
|
const requiredFields = ['extensionId', 'clientId', 'refreshToken'];
|
|
15
15
|
|
|
16
|
+
function throwIfNotOk(request, response) {
|
|
17
|
+
if (!request.ok) {
|
|
18
|
+
const error = new Error(request.statusText ?? 'Unknown error');
|
|
19
|
+
error.response = response;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
class APIClient {
|
|
17
25
|
constructor(options) {
|
|
18
26
|
if (typeof fetch !== 'function') {
|
|
@@ -46,7 +54,11 @@ class APIClient {
|
|
|
46
54
|
body: readStream,
|
|
47
55
|
});
|
|
48
56
|
|
|
49
|
-
|
|
57
|
+
const response = await request.json();
|
|
58
|
+
|
|
59
|
+
throwIfNotOk(request, response);
|
|
60
|
+
|
|
61
|
+
return response;
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
async publish(target = 'default', token = this.fetchToken()) {
|
|
@@ -57,7 +69,11 @@ class APIClient {
|
|
|
57
69
|
headers: this._headers(await token),
|
|
58
70
|
});
|
|
59
71
|
|
|
60
|
-
|
|
72
|
+
const response = await request.json();
|
|
73
|
+
|
|
74
|
+
throwIfNotOk(request, response);
|
|
75
|
+
|
|
76
|
+
return response;
|
|
61
77
|
}
|
|
62
78
|
|
|
63
79
|
async get(projection = 'DRAFT', token = this.fetchToken()) {
|
|
@@ -68,7 +84,11 @@ class APIClient {
|
|
|
68
84
|
headers: this._headers(await token),
|
|
69
85
|
});
|
|
70
86
|
|
|
71
|
-
|
|
87
|
+
const response = await request.json();
|
|
88
|
+
|
|
89
|
+
throwIfNotOk(request, response);
|
|
90
|
+
|
|
91
|
+
return response;
|
|
72
92
|
}
|
|
73
93
|
|
|
74
94
|
async fetchToken() {
|
|
@@ -91,6 +111,8 @@ class APIClient {
|
|
|
91
111
|
},
|
|
92
112
|
});
|
|
93
113
|
|
|
114
|
+
await throwIfNotOk(request);
|
|
115
|
+
|
|
94
116
|
const response = await request.json();
|
|
95
117
|
|
|
96
118
|
return response.access_token;
|