From 051e01b2a1dba69e1d315e5b51c97758a52de584 Mon Sep 17 00:00:00 2001 From: sergeymitr Date: Fri, 22 Sep 2023 18:48:58 +0000 Subject: [PATCH] Connection: offline mode for 127.0.0.1 and proper error messages (#32898) - Add 127.0.0.1 into the list of known offline domain names to force offline mode upon it - Display proper connection error message if trying to connect with a known local domain name Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/6277837184 --- CHANGELOG.md | 8 ++++++ components/connect-screen/basic/index.jsx | 2 ++ components/connect-screen/basic/visual.jsx | 29 +++++++++++++++++++--- package.json | 2 +- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba13470..607016a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ### This is a list detailing changes for the Jetpack RNA Connection Component releases. +## [0.30.0-alpha] - unreleased + +This is an alpha version! The changes listed here are not final. + +### Added +- Handle connection error codes and display proper error messages. Enabled for the "private network" error only at the moment. + ## [0.29.10] - 2023-09-13 ### Changed - Updated package dependencies. [#33001] @@ -628,6 +635,7 @@ - `Main` and `ConnectUser` components added. - `JetpackRestApiClient` API client added. +[0.30.0-alpha]: https://github.com/Automattic/jetpack-connection-js/compare/v0.29.10...v0.30.0-alpha [0.29.10]: https://github.com/Automattic/jetpack-connection-js/compare/v0.29.9...v0.29.10 [0.29.9]: https://github.com/Automattic/jetpack-connection-js/compare/v0.29.8...v0.29.9 [0.29.8]: https://github.com/Automattic/jetpack-connection-js/compare/v0.29.7...v0.29.8 diff --git a/components/connect-screen/basic/index.jsx b/components/connect-screen/basic/index.jsx index 2902860..f3d1774 100644 --- a/components/connect-screen/basic/index.jsx +++ b/components/connect-screen/basic/index.jsx @@ -58,6 +58,7 @@ const ConnectScreen = ( { const displayButtonError = Boolean( registrationError ); const buttonIsLoading = siteIsRegistering || userIsConnecting; + const errorCode = registrationError?.response?.code; return ( { buttonLabel, handleButtonClick, displayButtonError, + errorCode, buttonIsLoading, footer, isOfflineMode, logo, } = props; - const errorMessage = isOfflineMode - ? createInterpolateElement( __( 'Unavailable in Offline Mode', 'jetpack' ), { + const getErrorMessage = () => { + // Explicit error code takes precedence over the offline mode. + switch ( errorCode ) { + case 'fail_domain_forbidden': + case 'fail_ip_forbidden': + case 'fail_domain_tld': + case 'fail_subdomain_wpcom': + case 'siteurl_private_ip': + return __( + 'Your site host is on a private network. Jetpack can only connect to public sites.', + 'jetpack' + ); + } + + if ( isOfflineMode ) { + return createInterpolateElement( __( 'Unavailable in Offline Mode', 'jetpack' ), { a: ( { rel="noopener noreferrer" /> ), - } ) - : undefined; + } ); + } + }; + + const errorMessage = getErrorMessage( errorCode, isOfflineMode ); return ( {}, footer: null, isOfflineMode: false, diff --git a/package.json b/package.json index 56115e7..3795eee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@automattic/jetpack-connection", - "version": "0.29.10", + "version": "0.30.0-alpha", "description": "Jetpack Connection Component", "homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/connection/#readme", "bugs": {