From 7826a9df2fa8f58d2e5d15b0fbba66bbd8a5b09a Mon Sep 17 00:00:00 2001 From: Vraja Das Date: Wed, 11 Dec 2024 17:14:45 +0200 Subject: [PATCH] fix hasError for no internet connection --- .../components/SEMrushRelatedKeyphrasesModalContent.js | 3 +++ .../SEMrushRelatedKeyphrasesModalContent.test.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/packages/js/src/components/SEMrushRelatedKeyphrasesModalContent.js b/packages/js/src/components/SEMrushRelatedKeyphrasesModalContent.js index c44a5dfc720..87f377444b9 100644 --- a/packages/js/src/components/SEMrushRelatedKeyphrasesModalContent.js +++ b/packages/js/src/components/SEMrushRelatedKeyphrasesModalContent.js @@ -15,6 +15,9 @@ import SEMrushCountrySelector from "./modals/SEMrushCountrySelector"; * @returns {boolean} Whether or not the error property is present. */ export function hasError( response ) { + if ( response?.code === "invalid_json" ) { + return true; + } return ! isEmpty( response ) && "error" in response; } diff --git a/packages/js/tests/components/SEMrushRelatedKeyphrasesModalContent.test.js b/packages/js/tests/components/SEMrushRelatedKeyphrasesModalContent.test.js index 35efe968309..58f88fa3307 100644 --- a/packages/js/tests/components/SEMrushRelatedKeyphrasesModalContent.test.js +++ b/packages/js/tests/components/SEMrushRelatedKeyphrasesModalContent.test.js @@ -33,6 +33,14 @@ describe( "SEMrushRelatedKeyphrasesModalContent", () => { it( "returns that the limit has been reached", () => { const actual = SEMrushRelatedKeyphrasesModalContent.hasError( { error: "An error!", status: 500 } ); + expect( actual ).toBe( true ); + } ); + it( "returns true when there is no internet connection", () => { + const actual = SEMrushRelatedKeyphrasesModalContent.hasError( { + code: "invalid_json", + message: "The response is not a valid JSON response.", + } ); + expect( actual ).toBe( true ); } ); } );