Skip to content

Fix: Improve localStorage error handling in storageHelper.js#364

Open
FrankOHara43 wants to merge 2 commits intofossology:mainfrom
FrankOHara43:storagehelper-json-parse
Open

Fix: Improve localStorage error handling in storageHelper.js#364
FrankOHara43 wants to merge 2 commits intofossology:mainfrom
FrankOHara43:storagehelper-json-parse

Conversation

@FrankOHara43
Copy link
Copy Markdown

Description

After logging into the UI page hydration error was being rendered due to the localStorage value being missing or malformed.

Changes

-Added checks for null, undefined, and empty string values from localStorage.getItem(key).
-Wrapped JSON.parse in a try-catch block to prevent runtime errors if the stored value is not valid JSON.
-Added error logging for JSON parsing failures.

…compatibility

Signed-off-by: FrankOHara43 <aryaswaraj5@gmail.com>
Signed-off-by: FrankOHara43 <aryaswaraj5@gmail.com>
@BUDDHABHUSHAN23
Copy link
Copy Markdown

Hi @FrankOHara43 — I independently reproduced both of these issues today while setting up FOSSologyUI locally.
Tested on:

FOSSology backend v4.6.0.95 via Docker
Confirmed api/v2/tokens returns 400 with snake_case fields, 201 with camelCase
Confirmed storageHelper crashes with "undefined is not valid JSON" after login

Both fixes look correct. The camelCase change in src/api/auth.js resolves the v2 token issue and the try-catch in storageHelper.js resolves the post-login hydration crash.
Tested and verified locally ✅

@FrankOHara43
Copy link
Copy Markdown
Author

Thank you for testing it out!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants