react-native-update-cli 2.9.3 → 2.9.4
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/lib/api.js +23 -9
- package/lib/utils/http-helper.js +1 -1
- package/package.json +1 -1
- package/src/api.ts +32 -9
- package/src/utils/http-helper.ts +1 -1
package/lib/api.js
CHANGED
|
@@ -114,21 +114,30 @@ const closeSession = ()=>{
|
|
|
114
114
|
}
|
|
115
115
|
session = undefined;
|
|
116
116
|
};
|
|
117
|
+
function createRequestError(error, requestUrl) {
|
|
118
|
+
const message = typeof error === 'string' ? error : error instanceof Error ? error.message : String(error);
|
|
119
|
+
return new Error(`${message}\nURL: ${requestUrl}`);
|
|
120
|
+
}
|
|
117
121
|
async function query(url, options) {
|
|
118
122
|
const baseUrl = await _httphelper.getBaseUrl;
|
|
119
123
|
const fullUrl = `${baseUrl}${url}`;
|
|
120
|
-
|
|
124
|
+
let resp;
|
|
125
|
+
try {
|
|
126
|
+
resp = await (0, _nodefetch.default)(fullUrl, options);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
throw createRequestError(error, fullUrl);
|
|
129
|
+
}
|
|
121
130
|
const text = await resp.text();
|
|
122
131
|
let json;
|
|
123
132
|
try {
|
|
124
133
|
json = JSON.parse(text);
|
|
125
134
|
} catch (e) {}
|
|
126
135
|
if (resp.status !== 200) {
|
|
127
|
-
const message = (json == null ? void 0 : json.message) || resp.statusText
|
|
136
|
+
const message = (json == null ? void 0 : json.message) || resp.statusText || `HTTP ${resp.status}`;
|
|
128
137
|
if (resp.status === 401) {
|
|
129
|
-
throw
|
|
138
|
+
throw createRequestError((0, _i18n.t)('loginExpired'), fullUrl);
|
|
130
139
|
}
|
|
131
|
-
throw
|
|
140
|
+
throw createRequestError(message, fullUrl);
|
|
132
141
|
}
|
|
133
142
|
return json;
|
|
134
143
|
}
|
|
@@ -221,12 +230,17 @@ async function uploadFile(fn, key) {
|
|
|
221
230
|
// form.append('file', fileStream, {
|
|
222
231
|
// contentType: 'application/octet-stream',
|
|
223
232
|
// });
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
233
|
+
let res;
|
|
234
|
+
try {
|
|
235
|
+
res = await (0, _nodefetch.default)(realUrl, {
|
|
236
|
+
method: 'POST',
|
|
237
|
+
body: form
|
|
238
|
+
});
|
|
239
|
+
} catch (error) {
|
|
240
|
+
throw createRequestError(error, realUrl);
|
|
241
|
+
}
|
|
228
242
|
if (res.status > 299) {
|
|
229
|
-
throw
|
|
243
|
+
throw createRequestError(`${res.status}: ${res.statusText || 'Upload failed'}`, realUrl);
|
|
230
244
|
}
|
|
231
245
|
// const body = await response.json();
|
|
232
246
|
return {
|
package/lib/utils/http-helper.js
CHANGED
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -75,10 +75,25 @@ export const closeSession = () => {
|
|
|
75
75
|
session = undefined;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
+
function createRequestError(error: unknown, requestUrl: string) {
|
|
79
|
+
const message =
|
|
80
|
+
typeof error === 'string'
|
|
81
|
+
? error
|
|
82
|
+
: error instanceof Error
|
|
83
|
+
? error.message
|
|
84
|
+
: String(error);
|
|
85
|
+
return new Error(`${message}\nURL: ${requestUrl}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
78
88
|
async function query(url: string, options: fetch.RequestInit) {
|
|
79
89
|
const baseUrl = await getBaseUrl;
|
|
80
90
|
const fullUrl = `${baseUrl}${url}`;
|
|
81
|
-
|
|
91
|
+
let resp: fetch.Response;
|
|
92
|
+
try {
|
|
93
|
+
resp = await fetch(fullUrl, options);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
throw createRequestError(error, fullUrl);
|
|
96
|
+
}
|
|
82
97
|
const text = await resp.text();
|
|
83
98
|
let json: any;
|
|
84
99
|
try {
|
|
@@ -86,11 +101,11 @@ async function query(url: string, options: fetch.RequestInit) {
|
|
|
86
101
|
} catch (e) {}
|
|
87
102
|
|
|
88
103
|
if (resp.status !== 200) {
|
|
89
|
-
const message = json?.message || resp.statusText
|
|
104
|
+
const message = json?.message || resp.statusText || `HTTP ${resp.status}`;
|
|
90
105
|
if (resp.status === 401) {
|
|
91
|
-
throw
|
|
106
|
+
throw createRequestError(t('loginExpired'), fullUrl);
|
|
92
107
|
}
|
|
93
|
-
throw
|
|
108
|
+
throw createRequestError(message, fullUrl);
|
|
94
109
|
}
|
|
95
110
|
return json;
|
|
96
111
|
}
|
|
@@ -195,13 +210,21 @@ export async function uploadFile(fn: string, key?: string) {
|
|
|
195
210
|
// contentType: 'application/octet-stream',
|
|
196
211
|
// });
|
|
197
212
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
213
|
+
let res: fetch.Response;
|
|
214
|
+
try {
|
|
215
|
+
res = await fetch(realUrl, {
|
|
216
|
+
method: 'POST',
|
|
217
|
+
body: form,
|
|
218
|
+
});
|
|
219
|
+
} catch (error) {
|
|
220
|
+
throw createRequestError(error, realUrl);
|
|
221
|
+
}
|
|
202
222
|
|
|
203
223
|
if (res.status > 299) {
|
|
204
|
-
throw
|
|
224
|
+
throw createRequestError(
|
|
225
|
+
`${res.status}: ${res.statusText || 'Upload failed'}`,
|
|
226
|
+
realUrl,
|
|
227
|
+
);
|
|
205
228
|
}
|
|
206
229
|
|
|
207
230
|
// const body = await response.json();
|