Skip to content

Commit

Permalink
fix hasError for no internet connection
Browse files Browse the repository at this point in the history
  • Loading branch information
vraja-pro committed Dec 11, 2024
1 parent 44eae7e commit 7826a9d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );
} );
Expand Down

0 comments on commit 7826a9d

Please sign in to comment.