Skip to content
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

Nicer error handling #1024

Merged
merged 38 commits into from
May 23, 2023

Conversation

SleeplessOne1917
Copy link
Member

I took up Nutomic's offer and implemented what was being implemented in #1013.
This is what the 404 error page looks like:
404-error-light

This is for a 500 error:
500-error-light

Besides making the error pages, I made it so that making sure an authenticated route has expected behavior with logouts and redirects only requires a change to one place. This should hopefully help make things easier to maintain.

@SleeplessOne1917 SleeplessOne1917 linked an issue May 16, 2023 that may be closed by this pull request
@dessalines
Copy link
Member

dessalines commented May 16, 2023

Whoa nice! These look really good.

I should be able to test later today.

import { ErrorPageData, setIsoData } from "../../utils";
import { ErrorPage } from "../app/error-page";

class ErrorGuard extends Component<any, any> {
Copy link
Member Author

Choose a reason for hiding this comment

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

I just thought of something. I could probably handle this on the server. It would probably both reduce bundle size and make my hacky use of 'routeData' unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

I just know that the server will return the json {"error: "string"}, for any failed request. Not sure how that translates for this.

In jerboa at least, all these errors do proper exception throws, so I can catch them, read the error message, and do actions based on that.

Copy link
Member Author

@SleeplessOne1917 SleeplessOne1917 May 21, 2023

Choose a reason for hiding this comment

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

My comment was unclear. I meant on the server side of the UI app that serves the pages, but not the actual Lemmy server.

As to doing different actions based on different error messages, that's definitely doable. We just need to define what should be done for those error messages. At the very least there should be a way to handle displaying that a user is banned (I even think there's an open issue for that).

@SleeplessOne1917
Copy link
Member Author

@dessalines before you merge, I'd like to give what I mentioned here a try.

@SleeplessOne1917
Copy link
Member Author

I've tried making the previously mentioned change. It wasn't quite what I was going for, but I think its an improvement over how I originally handled isoData.

@SleeplessOne1917
Copy link
Member Author

@dessalines I almost forgot: I'm going to have to add translations for those error messages.

@Nutomic
Copy link
Member

Nutomic commented May 17, 2023

That looks great! But please dont link to the issue tracker, it will lead to a lot of issues opened for tech support. Instead it can link to !lemmy_support and the Matrix chat. That way users can help each other and devs dont have to help with every little problem.

@@ -61,6 +61,7 @@
"isomorphic-cookie": "^1.2.4",
"jwt-decode": "^3.1.2",
"lemmy-js-client": "0.17.2-rc.17",
"lodash": "^4.17.21",
Copy link
Member

Choose a reason for hiding this comment

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

lodash seems unused, and I'd def like to avoid it if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

lodash is only being used in webpack.config.js. I originally tried having it as a dev dependency, but this caused issues when I tested the prod Dockerfile. This shouldn't be included in the bundle.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah i got this issue too when trying to run docker compose against lemmy-ui

src/shared/components/app/error-page.tsx Outdated Show resolved Hide resolved
src/shared/components/common/error-guard.tsx Outdated Show resolved Hide resolved
import { ErrorPageData, setIsoData } from "../../utils";
import { ErrorPage } from "../app/error-page";

class ErrorGuard extends Component<any, any> {
Copy link
Member

Choose a reason for hiding this comment

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

I just know that the server will return the json {"error: "string"}, for any failed request. Not sure how that translates for this.

In jerboa at least, all these errors do proper exception throws, so I can catch them, read the error message, and do actions based on that.

src/shared/utils.ts Show resolved Hide resolved
Copy link
Member

@dessalines dessalines 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 to me. I'll let nutomic also look at this one.

@dessalines dessalines requested a review from Nutomic May 21, 2023 21:50
// in production will get a more generic message.
if (process.env.NODE_ENV === "development") {
errorPageData.error = error;
}
Copy link
Member

Choose a reason for hiding this comment

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

Im not sure this makes sense. The reason not to show error messages is usually for security, but anyway the error messages are available if you use the API directly.

Another reason might be to keep things simple for non-techie users. But even if they dont understand the error, there can be a text telling them to copy-paste the error message to admins/devs. That can be very helpful for debugging.

@SleeplessOne1917
Copy link
Member Author

@Nutomic @dessalines I made a blurb for the error code. Here is what it looks like:
image

If you like the verbiage, I'll submit a translation. On the topic of errors, I have an idea for Lemmy errors that I'm looking for feedback on.

@dessalines
Copy link
Member

dessalines commented May 22, 2023

Looks good to me.

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.

Have a 500 error page for server errors
4 participants