Skip to content

Commit 17816f7

Browse files
authored
fix(cli): improve validateNextWordPressUrl error messages (#2205)
1 parent c63cb6a commit 17816f7

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

.changeset/salty-files-build.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@faustwp/cli': patch
3+
---
4+
5+
Improve validateNextWordPressUrl error messages by including HTTP status code and status text, also providing an additional clarity for fatal errors.

package-lock.json

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

packages/faustwp-cli/src/healthCheck/validateNextWordPressUrl.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { errorLog, warnLog } from '../stdout/index.js';
55
* Validates the NEXT_PUBLIC_WORDPRESS_URL environment variable by sending a POST request to the Faust Plugin API.
66
* If the URL matches the Faust Plugin Headless URL, the validation fails, and an error is logged.
77
*/
8+
9+
const FAILED_VALIDATION_MESSAGE = 'Validation Failed, Faust is shutting down:';
10+
811
export async function validateNextWordPressUrl(): Promise<void> {
912
const apiUrl = `${getWpUrl()}/wp-json/faustwp/v1/validate_public_wordpress_url`;
1013
const headers = {
@@ -23,6 +26,13 @@ export async function validateNextWordPressUrl(): Promise<void> {
2326
});
2427

2528
if (!response.ok) {
29+
errorLog(
30+
'Validation error:',
31+
String(response.status),
32+
'-',
33+
response.statusText,
34+
);
35+
2636
if (response.status === 404) {
2737
// Handle the case when the route does not exist
2838
warnLog(
@@ -31,11 +41,14 @@ export async function validateNextWordPressUrl(): Promise<void> {
3141
} else if (response.status >= 500 && response.status < 600) {
3242
// Handle WordPress server error
3343
errorLog(
44+
FAILED_VALIDATION_MESSAGE,
3445
'Could not connect to the WordPress server. Please check your WordPress URL or server status, as your site may not function correctly.',
3546
);
47+
process.exit(1);
3648
} else {
3749
errorLog(
38-
'Validation Failed: Your Faust front-end site URL value is misconfigured. It should NOT match the `NEXT_PUBLIC_WORDPRESS_URL.`',
50+
FAILED_VALIDATION_MESSAGE,
51+
'Your Faust front-end site URL value is misconfigured. It should NOT match the `NEXT_PUBLIC_WORDPRESS_URL.`',
3952
);
4053
process.exit(1);
4154
}

0 commit comments

Comments
 (0)