@uxf/scripts 1.5.3 → 1.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/scripts",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -7,7 +7,7 @@ const cheerio = require("cheerio");
7
7
 
8
8
  /**
9
9
  *
10
- * @typedef {{parentUrl: (string | undefined), isImg: boolean, time: number, ttl: number, url: string, status: number}} UrlCheckResponse
10
+ * @typedef {{parentUrl: (string | undefined), isImg: boolean, time: number, ttl: number, url: string, status: number, message: (string | undefined)}} UrlCheckResponse
11
11
  */
12
12
 
13
13
  const MAX_TTL = 3;
@@ -39,7 +39,7 @@ function isImageUrl(url) {
39
39
  * @return {string}
40
40
  */
41
41
  function createErrorList(errors) {
42
- return errors.map(err => `${createTabSpace(3)}${err.url}${createTabSpace()}${err.status}`).join("\n");
42
+ return errors.map(err => `${createTabSpace(3)}${err.url}${createTabSpace()}${err.status}${err.message ? ` – ${err.message}` : ""}`).join("\n");
43
43
  }
44
44
 
45
45
  /**
@@ -114,8 +114,8 @@ async function fetchUrl(url, parentUrl = undefined, ttl = 1) {
114
114
  const { status } = await Sitemap.axios.get(url);
115
115
  const t1 = performance.now();
116
116
 
117
- if (status !== 200) {
118
- throw new Error("Status must be 200");
117
+ if (status !== 200 && ttl < MAX_TTL) {
118
+ return await fetchUrl(url, parentUrl, ttl + 1);
119
119
  }
120
120
 
121
121
  return {
@@ -127,17 +127,14 @@ async function fetchUrl(url, parentUrl = undefined, ttl = 1) {
127
127
  time: Math.ceil(t1 - t0),
128
128
  };
129
129
  } catch (e) {
130
- if (ttl < MAX_TTL) {
131
- return fetchUrl(url, parentUrl, ttl + 1);
132
- }
133
-
134
130
  return {
135
131
  url,
136
132
  parentUrl,
137
133
  isImg: isImageUrl(url),
138
134
  ttl,
139
- status: Number.parseInt((e && e.response && e.response.status) || "0"),
135
+ status: Number.parseInt((e && e.response && e.response.status) || -1, 10),
140
136
  time: 0,
137
+ message: e.message,
141
138
  };
142
139
  }
143
140
  }
@@ -244,8 +241,8 @@ function printUrlInfo(url, urlIndex, allUrlsCount, prefix = "") {
244
241
  * @param result {UrlCheckResponse}
245
242
  */
246
243
  function printUrlResult(result) {
247
- const { ttl, status, time } = result;
248
- stdout.write(`${createTabSpace()}${status} (${time}ms) ttl=${ttl} ${status === 200 ? "✅ " : "❌ "}\n`);
244
+ const { ttl, status, time, message } = result;
245
+ stdout.write(`${createTabSpace()}${status}${message ? " – " + message : ""} (${time}ms) ttl=${ttl} ${status === 200 ? "✅ " : "❌ "}\n`);
249
246
  }
250
247
 
251
248
  /**