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 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
- const resp = await (0, _nodefetch.default)(fullUrl, options);
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 new Error((0, _i18n.t)('loginExpired'));
138
+ throw createRequestError((0, _i18n.t)('loginExpired'), fullUrl);
130
139
  }
131
- throw new Error(message);
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
- const res = await (0, _nodefetch.default)(realUrl, {
225
- method: 'POST',
226
- body: form
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 new Error(`${res.status}: ${res.statusText}`);
243
+ throw createRequestError(`${res.status}: ${res.statusText || 'Upload failed'}`, realUrl);
230
244
  }
231
245
  // const body = await response.json();
232
246
  return {
@@ -65,7 +65,7 @@ const ping = async (url)=>{
65
65
  if (!pingFinished) {
66
66
  // console.log('ping timeout', url);
67
67
  }
68
- }, 2000))
68
+ }, 5000))
69
69
  ]);
70
70
  };
71
71
  const testUrls = async (urls)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "2.9.3",
3
+ "version": "2.9.4",
4
4
  "description": "command line tool for react-native-update (remote updates for react native)",
5
5
  "main": "lib/exports.js",
6
6
  "types": "lib/exports.d.ts",
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
- const resp = await fetch(fullUrl, options);
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 new Error(t('loginExpired'));
106
+ throw createRequestError(t('loginExpired'), fullUrl);
92
107
  }
93
- throw new Error(message);
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
- const res = await fetch(realUrl, {
199
- method: 'POST',
200
- body: form,
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 new Error(`${res.status}: ${res.statusText}`);
224
+ throw createRequestError(
225
+ `${res.status}: ${res.statusText || 'Upload failed'}`,
226
+ realUrl,
227
+ );
205
228
  }
206
229
 
207
230
  // const body = await response.json();
@@ -48,7 +48,7 @@ export const ping = async (url: string) => {
48
48
  if (!pingFinished) {
49
49
  // console.log('ping timeout', url);
50
50
  }
51
- }, 2000),
51
+ }, 5000),
52
52
  ),
53
53
  ]) as Promise<string | null>;
54
54
  };