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

[Refactor] Fix clippy::too_many_arguments and rework error page rendering #529

Merged
merged 3 commits into from Aug 31, 2021

Conversation

aliemjay
Copy link
Contributor

@aliemjay aliemjay commented May 12, 2021

Too many arguments are moved around and many of them are already stored in MiniserveConfig. Many of these are used to render error pages.

To fix this issue, it was necessary to rework error page rendering:

  1. Implement ResponseError for ContextualError so that it can be
    returned from service handlers as is and will then be automatically
    logged to the console and converted into an error response.

  2. At service handler level, all error responses are now rendered as
    plain text.

  3. error_page_middleware is now responsible for the rendering of the
    final error page from plain text responses.

Based on #513

Closes #588

@aliemjay
Copy link
Contributor Author

Hi @svenstaro,

I currently base my new PRs on some previous PRs to avoid huge merge conflicts when merging. What do you think of such workflow? I found this necessary because PRs are piling up.

@aliemjay
Copy link
Contributor Author

Is such code refactoring welcome? I hope it is not invasive!

@aliemjay aliemjay changed the title Fix clippy::too_many_arguments Fix clippy::too_many_arguments and Rework error page rendering May 18, 2021
@aliemjay aliemjay changed the title Fix clippy::too_many_arguments and Rework error page rendering [Refactor] Fix clippy::too_many_arguments and rework error page rendering May 28, 2021
src/errors.rs Outdated Show resolved Hide resolved
@aliemjay aliemjay force-pushed the src-refactor branch 2 times, most recently from d83e429 to 168b686 Compare August 30, 2021 02:53
@aliemjay
Copy link
Contributor Author

@svenstaro I hope this gets reviewed next

@svenstaro
Copy link
Owner

Sure but let's get #500 in first. We're almost there! \o/

Copy link
Owner

@svenstaro svenstaro left a comment

Choose a reason for hiding this comment

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

I get a plain (unthemed) error page for invalid or missing auth here. Granted, this also was the previous behavior but how about we fix this in the same PR? The 404 error, for instance, is already themed. It would make sense for 401/403 to also be themed and it would be more consistent, too.

@svenstaro
Copy link
Owner

While testing this, I noticed #588 which you could address in this PR as well (or it could just be a follow-up).

@aliemjay
Copy link
Contributor Author

I get a plain (unthemed) error page for invalid or missing auth here. Granted, this also was the previous behavior but how about we fix this in the same PR? The 404 error, for instance, is already themed. It would make sense for 401/403 to also be themed and it would be more consistent, too.

Is it even possible to get themed in invalid auth? I mean unless we embed css.

@aliemjay
Copy link
Contributor Author

While testing this, I noticed #588 which you could address in this PR as well (or it could just be a follow-up).

This should be easy. I'll implement it here.

@svenstaro
Copy link
Owner

I get a plain (unthemed) error page for invalid or missing auth here. Granted, this also was the previous behavior but how about we fix this in the same PR? The 404 error, for instance, is already themed. It would make sense for 401/403 to also be themed and it would be more consistent, too.

Is it even possible to get themed in invalid auth? I mean unless we embed css.

I suppose the internal route to the media resources doesn't really need to be protected, no secrets will ever be kept there. The theme information is stored inside the browser itself so that should also be always available.

@svenstaro
Copy link
Owner

The rest of it looks like a vast improvement to me! Probably there are some parts which could be golfed a little (like the middleware bit) but I wouldn't immediately know how to best golf it.


div.error {
p { (error_code.to_string()) }
@for error in error_description.lines() {
p { (error) }
}
@if display_back_link {
// WARN don't expose random route!
@if !conf.random_route.is_some() {
Copy link
Owner

Choose a reason for hiding this comment

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

Good catch!

@aliemjay aliemjay force-pushed the src-refactor branch 2 times, most recently from d716163 to 5a87886 Compare August 30, 2021 06:14
@svenstaro
Copy link
Owner

I snuck in #542. Could you rebase on top of that? Sorry!

... page rendering

Too many arguments are moved around and many of them are already stored
in MiniserveConfig. Many of these are used to render error pages.

To fix this issue, it was necessary to rework error page rendering:

1. Implement `ResponseError` for `ContextualError` so that it can be
   returned from service handlers as is and will then be automatically
   logged to the console and converted into an error response.

2. At service handler level, all error responses are now rendered as
   plain text.

3. 'error_page_middleware' is now responsible for the rendering of the
   final error page from plain text reponses.

Signed-off-by: Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com>
@aliemjay
Copy link
Contributor Author

#588 and themed 401 page should be fixed

@svenstaro svenstaro merged commit 1e4230e into svenstaro:master Aug 31, 2021
@svenstaro
Copy link
Owner

Very cool!

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.

Error page isn't rendered with the correct theme
2 participants