Fix/login 403 logged in and 401 when not logged in#711
Open
SharonStrats wants to merge 3 commits intomainfrom
Open
Fix/login 403 logged in and 401 when not logged in#711SharonStrats wants to merge 3 commits intomainfrom
SharonStrats wants to merge 3 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses the confusing 401 and 403 error messages displayed to users when they are logged out (401) or logged in but lack permissions (403). Instead of showing alarming alert() popups and throwing errors, the code now logs friendlier messages and gracefully continues execution.
Changes:
- In
ensureLoadedPreferences, the 401/unauthorized handling now sets a warning and returns context instead of showing an alert, and adds regex-based fallback matching for error messages. - In
ensureLoadedProfile, the function no longer throws when the user is not logged in; instead it logs a message and returns context. Additionally, 403/forbidden and cancel errors during profile loading are treated as non-fatal when the user is already authenticated. - Error message display in
ensureLoadedProfile's catch block is updated to use a safely extracted message string instead of accessingerr.messagedirectly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
src/login/login.ts
Outdated
| ( | ||
| err instanceof CrossOriginForbiddenError || | ||
| err instanceof SameOriginForbiddenError || | ||
| /status:\s*403|forbidden/i.test(message) || |
| let m2: string | ||
| if (err instanceof UnauthorizedError) { | ||
| const errorMessage = err instanceof Error ? err.message : `${err}` | ||
| if (err instanceof UnauthorizedError || /status:\s*401|unauthorized/i.test(errorMessage)) { |
| context.publicProfile = await loadProfile(logInContext.me) | ||
| } catch (err) { | ||
| const message = err instanceof Error ? err.message : `${err}` | ||
| if (/status:\s*401|unauthorized/i.test(message)) { |
Comment on lines
+190
to
+206
| const notLoggedInMessage = 'Not logged in, so profile was not loaded.' | ||
| debug.log(notLoggedInMessage) | ||
| if (context.div && context.dom) { | ||
| context.div.appendChild(widgets.errorMessageBlock(context.dom, notLoggedInMessage)) | ||
| } | ||
| return context | ||
| } | ||
| context.publicProfile = await loadProfile(logInContext.me) | ||
| } catch (err) { | ||
| const message = err instanceof Error ? err.message : `${err}` | ||
| if (/status:\s*401|unauthorized/i.test(message)) { | ||
| const notLoggedInMessage = 'Not logged in, so profile was not loaded.' | ||
| debug.warn(notLoggedInMessage) | ||
| if (context.div && context.dom) { | ||
| context.div.appendChild(widgets.errorMessageBlock(context.dom, notLoggedInMessage)) | ||
| } | ||
| return context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I get all these red 403 and 401 errors when I'm
these are quite confronting, this is an attempt at messaging instead of the confronting errors.