- Notifications
You must be signed in to change notification settings - Fork929
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from6 commits
196ac96
b6f2e5a
3a7dd2d
0f47a34
50404ee
1b8cf2a
94907f2
169d41c
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
thinking of this in the context of using the CLI or the API directly, "page" doesn't make a ton of sense | ||||||
}) | ||||||
} | ||||||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,55 @@ | ||
import AlertTitle from "@mui/material/AlertTitle"; | ||
import { getErrorDetail, getErrorMessage, getErrorStatus } from "api/errors"; | ||
import type { FC } from "react"; | ||
import { Link } from "../Link/Link"; | ||
import { Alert, AlertDetail, type AlertProps } from "./Alert"; | ||
export const ErrorAlert: FC< | ||
Omit<AlertProps, "severity" | "children"> & { error: unknown } | ||
> = ({ error, ...alertProps }) => { | ||
const message = getErrorMessage(error, "Something went wrong."); | ||
const detail = getErrorDetail(error); | ||
const status = getErrorStatus(error); | ||
// For some reason, the message and detail can be the same on the BE, but does | ||
// not make sense in the FE to showing them duplicated | ||
const shouldDisplayDetail = message !== detail; | ||
const body = () => { | ||
// When the error is a Forbidden response we include a link for the user to | ||
// go back to a known viewable page. | ||
// 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
return ( | ||
<> | ||
<AlertTitle>{message}</AlertTitle> | ||
<AlertDetail> | ||
{detail}{" "} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I know theoretically we're now always setting | ||
<Link href="/workspaces" className="w-fit"> | ||
Go to workspaces | ||
</Link> | ||
</AlertDetail> | ||
</> | ||
); | ||
} | ||
if (detail) { | ||
return ( | ||
<> | ||
<AlertTitle>{message}</AlertTitle> | ||
{shouldDisplayDetail && <AlertDetail>{detail}</AlertDetail>} | ||
</> | ||
); | ||
} | ||
return message; | ||
}; | ||
return ( | ||
<Alert severity="error" {...alertProps}> | ||
{body()} | ||
Member
| ||
</Alert> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const Language = { | ||
emailLabel: "Email", | ||
passwordLabel: "Password", | ||
usernameLabel: "Username", | ||
nameLabel: "Full name", | ||
emailInvalid: "Please enter a valid email address.", | ||
emailRequired: "Please enter an email address.", | ||
passwordRequired: "Please enter a password.", | ||
createUser: "Create", | ||
cancel: "Cancel", | ||
}; |
Uh oh!
There was an error while loading.Please reload this page.