Skip to content

fix: include a link and more useful error details for 403 response codes #16644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

brettkolodny
Copy link
Contributor

Currently if a user gets to a page they don't have permission to view they're greeted with a vague error alert and no actionable items. This PR adds a link back to /workspaces within the alert as well as more helpful error details.

Before:
Screenshot 2025-02-20 at 11 06 06 AM

After:
Screenshot 2025-02-20 at 11 06 19 AM

@brettkolodny brettkolodny changed the title fix: include a link to /workspaces and more useful error details for 403 response codes fix: include a link and more useful error details for 403 response codes Feb 20, 2025
@brettkolodny brettkolodny marked this pull request as draft February 20, 2025 17:49
@brettkolodny brettkolodny marked this pull request as ready for review February 21, 2025 20:31
Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛳️

@@ -154,6 +154,7 @@ func ResourceNotFound(rw http.ResponseWriter) {
func Forbidden(rw http.ResponseWriter) {
Write(context.Background(), rw, http.StatusForbidden, codersdk.Response{
Message: "Forbidden.",
Detail: "You don't have permission to view this page. If you believe this is a mistake, please contact your administrator or try signing in with different credentials.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Detail: "You don't have permission to view this page. If you believe this is a mistake, please contact your administrator or try signing in with different credentials.",
Detail: "You don't have permission to view this content. If you believe this is a mistake, please contact your administrator or try signing in with different credentials.",

thinking of this in the context of using the CLI or the API directly, "page" doesn't make a ton of sense

<>
<AlertTitle>{message}</AlertTitle>
<AlertDetail>
{detail}{" "}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know theoretically we're now always setting Detail for 403 responses, but what if it comes back undefined from some endpoint that doesn't use httpapi.Forbidden when it should? do we care about handling that? maybe we don't and it's fine 🤷‍♀️

Copy link
Member

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just had one main question


return (
<Alert severity="error" {...alertProps}>
{body()}
Copy link
Member

@Parkreiner Parkreiner Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't know your opinion on ternaries, but I feel like the typical React way of doing this would be to inline everything into a single return statement:

return (
  <Alert severity="error" {...alterProps}>
    {status === 403
      ? (
        <-- JSX -->
        )
      : detail ?
        (
        <-- JSX -->
        )
      : (
        message
      )
  </Alert>
);

Prettier/Biome should be able to format the ternaries to make them more readable than this, but you get the idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm usually pro ternary but I've been trying to match other general vibes of the code base. Generally though I think I've started to learn towards if the logic is more than an "if/else" it's more readable being broken out

// Additionally since the error messages and details from the server can be
// missing or confusing for an end user we render a friendlier message
// regardless of the response from the server.
if (status === 403) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this as a baseline solution, but do you know if there are ever cases where it makes sense to redirect the user to a page more relevant to what they were trying to access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, and I'm actually working on a PR right now that will make RequirePermissions a bit more user friendly in that way. But this change is still relevant in the cases where we don't wrap a portion of the page in RequirePermissions

@brettkolodny brettkolodny merged commit a376e8d into main Feb 21, 2025
33 checks passed
@brettkolodny brettkolodny deleted the brett/improve-erroralert-to-include-a-redirect-button branch February 21, 2025 21:26
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants