Skip to content

Commit d155865

Browse files
committed
Merge branch 'release/0.7.6'
2 parents 845e3b7 + 95f0189 commit d155865

4 files changed

Lines changed: 41 additions & 24 deletions

File tree

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
## v0.7.5 (2024-06-27)
10+
11+
### Changed
12+
13+
- Display the original error message when a request fails ([#14](https://github.com/studiometa/cli-test-redirection/pull/14), [f087a63](https://github.com/studiometa/cli-test-redirection/commit/f087a63))
14+
915
## v0.7.5 (2023-12-20)
1016

1117
### Fixed

β€Žpackage-lock.jsonβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@studiometa/cli-test-redirection",
3-
"version": "0.7.5",
3+
"version": "0.7.6",
44
"publishConfig": {
55
"access": "public"
66
},

β€Žsrc/index.jsβ€Ž

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,35 @@ const DIFF_OPTIONS = {
3333
*/
3434
async function getFinalRedirect(url, method = 'GET') {
3535
return new Promise((resolve, reject) => {
36-
let cmd = `curl -o /dev/null -sL -k -w "%{url_effective}" -X ${method} -I "${url}"`;
36+
let cmd = `curl --output /dev/null --silent --show-error --fail --location --write-out '{"data":%{json},"headers":%{header_json}}' --user-agent 'studiometa/cli-test-redirection bot' --request ${method} "${url}"`;
3737

3838
if (OPTIONS.user) {
3939
cmd += ` --user ${OPTIONS.user}`;
4040
}
4141

42-
exec(cmd, (error, out) => {
42+
exec(cmd, (error, stdout) => {
43+
const out = JSON.parse(stdout);
4344
if (error) {
4445
if (OPTIONS.verbose) {
46+
console.log(chalk.red('[ERROR]', chalk.underline(url)));
47+
console.log(chalk.red('[ERROR]', out.data.errormsg));
48+
if (out.data.http_code >= 500) {
49+
console.log(
50+
chalk.red(
51+
`[ERROR] The error probably comes from a syntax error in your .htaccess file.`
52+
)
53+
);
54+
}
4555
console.log(
4656
chalk.red(
47-
'An error occured while doing a request. This might be caused by an infinite redirection loop.'
57+
'[ERROR] Try running the following command to confirm the error:\n'
4858
)
4959
);
50-
console.log(
51-
chalk.red('Try running the following command to confirm this:\n')
52-
);
5360
console.log(chalk.red(`\tcurl -sIL -X ${method} "${url}"\n`));
54-
console.log(chalk.red(error.message));
5561
}
5662
reject({ error, url, method, cmd, out });
5763
}
58-
resolve(decodeURI(out));
64+
resolve(out);
5965
});
6066
});
6167
}
@@ -129,12 +135,13 @@ async function redirectionTest({ options, total }) {
129135
}
130136

131137
return new Promise(async (resolve, reject) => {
132-
let out;
138+
let out, error, url;
133139

134140
try {
135141
out = await getFinalRedirect(from, options.method);
136-
} catch (error) {
137-
out = error;
142+
url = out.data.url_effective;
143+
} catch (err) {
144+
error = err;
138145
}
139146

140147
if (OPTIONS.ignoreQueryParameters || options.ignoreQueryParameters) {
@@ -150,10 +157,12 @@ async function redirectionTest({ options, total }) {
150157
`[${current.toString().padStart(total.toString().length)}/${total}]`
151158
);
152159

153-
if (typeof out !== 'string') {
154-
const msg = `πŸ” ${chalk.white(from)} \n β†’ ${chalk.magenta(
160+
if (error) {
161+
const msg = `❌ ${chalk.white(from)} \n β†’ ${chalk.red('-')} ${chalk.red.strikethrough(
155162
to
156-
)} \n β†’ ${chalk.magentaBright(out.out)} (potential infinite loop)`;
163+
)} \n β†’ ${chalk.magentaBright('+ ' + error.out.data.url)} (${
164+
error.out.data.errormsg
165+
})`;
157166

158167
if (!OPTIONS.verbose) {
159168
printError(count + ' ' + msg);
@@ -163,11 +172,13 @@ async function redirectionTest({ options, total }) {
163172

164173
await delayingFn(OPTIONS.delay);
165174
reject({ msg, from, to, out });
166-
} else if (out !== to) {
167-
const msg = `🚫 ${chalk.white(from)} \n β†’ ${chalk.red('-')} ${chalk.red.strikethrough(
168-
to
169-
)} \n β†’ ${chalk.magentaBright(`+ ${out}`)}`;
170-
const diff = diffStringsUnified(to, out, DIFF_OPTIONS);
175+
} else if (url !== to) {
176+
const msg = `🚫 ${chalk.white(from)} \n β†’ ${chalk.red(
177+
'-'
178+
)} ${chalk.red.strikethrough(to)} \n β†’ ${chalk.magentaBright(
179+
`+ ${url}`
180+
)}`;
181+
const diff = diffStringsUnified(to, url, DIFF_OPTIONS);
171182

172183
if (!OPTIONS.verbose) {
173184
printError(count + ' ' + msg); // write text
@@ -176,7 +187,7 @@ async function redirectionTest({ options, total }) {
176187
}
177188

178189
await delayingFn(OPTIONS.delay);
179-
reject({ msg, from, to, out, diff });
190+
reject({ msg, from, to, url, diff });
180191
} else {
181192
const msg = `βœ… ${chalk.white(from)} \n ${chalk.black('β†’')} ${chalk.blue(
182193
to
@@ -191,7 +202,7 @@ async function redirectionTest({ options, total }) {
191202
}
192203

193204
await delayingFn(OPTIONS.delay);
194-
resolve({ msg, from, to, out });
205+
resolve({ msg, from, to, url });
195206
}
196207
});
197208
}

0 commit comments

Comments
Β (0)