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

Improve 404 handling #310

Merged
merged 22 commits into from
Jan 14, 2019
Merged

Conversation

parostatkiem-zz
Copy link
Contributor

@parostatkiem-zz parostatkiem-zz commented Dec 31, 2018

Description

lerna bootstrap required!

Changes proposed in this pull request:

  • Alert has a ttl property which lets it survive n redirects (set to 1)
  • Microfrontend developer can define a custom behaviour (function) when page is not found (404)
  • Could not map the exact target... error appears when user tries to enter a route with a defaultChildNode at the end and he's redirected to that node.
  • Migrate to Babel 7.0 and @babel/preset-env to be able to use spread operator
  • Design a fancy, isolated 404 page (uncomment extendedConfiguration.js::583 to be able to see it)

Related issue(s)

Resolves #310, #281

Copy link
Contributor

@dariadomagala-sap dariadomagala-sap left a comment

Choose a reason for hiding this comment

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

One additional bug that I found during the review - when going to 'partially wrong link' from the browsers address bar (not using Luigi client), the frame is loaded twice. I think it works the same way on master, so it's not your implementations fault, although maybe it would be good to fix it within this task.

@@ -264,3 +270,24 @@ export const handleRouteClick = node => {
navigateTo(route);
}
};

const ShowNotExactRouteError = async (
Copy link
Contributor

Choose a reason for hiding this comment

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

All variables start with lowercase letter, so could you please rename it to showNotExactRouteError to consistency?

}
//the path is unrecognized at all and cannot be fitted to any known one
const custom404handler = LuigiConfig.getConfigValue(
'settings.handle404'
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename handle404 since all functions in our config are nouns. 404handler or something like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

And I think that 404 handler should be part of navigation, not settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

404handler was the first name I thought about but variable names can't start with number.
I decided to place it in settings because, in my opinion, it's not related to navigation. Any other suggestions about the name? I've got no idea what I should change it to :D


component.set({ alert });
navigateTo('/');
if (defaultChildNode && pathData.navigationPath.length > 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this pathData.navigationPath.length > 2 for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. In case (probably impossible) pathData.navitationPath was empty, there will be no errors.
  2. I've just changed it to 1 because overview is a defaultChild for /. If it was set to >0 or not present at all, "Could not find exact route" error would appear instead of "Could not find requested route" due to automatic redirection to /.

Thanks for noticing 2 was the wrong number 👍

Copy link
Contributor

@jesusreal jesusreal Jan 7, 2019

Choose a reason for hiding this comment

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

I would rather create a variable out of pathData.navigationPath.length > 1 to make clear what we are checking here through the variable name.

@maxmarkus
Copy link
Contributor

Design a fancy, isolated 404 page (uncomment extendedConfiguration.js::583 to be able to see it)
Currently the fancy isolated 404 page is enabled, do we want to enable it by default?

@maxmarkus maxmarkus self-assigned this Jan 2, 2019
Copy link
Contributor

@maxmarkus maxmarkus left a comment

Choose a reason for hiding this comment

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

Check the comments please.


window.addEventListener('popstate', async e => {
const alert = this.get().alert;
if (alert && alert.ttl !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use typeof number here, just to be save.

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'd love to use isInteger() but Internet Explorer's compatibility blocks me from doing this :(

Copy link
Contributor

@dariadomagala-sap dariadomagala-sap left a comment

Choose a reason for hiding this comment

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

Right now it doesn't work for 'partially wrong link'

@@ -320,6 +320,11 @@ var projectsNavProviderFn = function(context) {
});
};

var customPageNotFoundHandler = function(wrongPath, wasAnyPathFitted) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be good to add to documentation that this function might receive wrongPath and wasAnyPathFitted?

: 'Could not find the requested route',
link: notFoundPath,
ttl: pathToRedirect === '/' ? 2 : 1 //how many redirections the alert will 'survive'.
//Redirecting to '/' causes another redirection to '/overview', that's why TTL needs to be bigger
Copy link
Contributor

Choose a reason for hiding this comment

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

In our case it's ok, because we don't have a view for '/', so it redirects to '/overview', but what if someone has a view on '/' and doesn't have this additional redirection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔

Copy link
Contributor

@bszwarc bszwarc left a comment

Choose a reason for hiding this comment

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

Minor comments

docs/navigation-configuration.md Outdated Show resolved Hide resolved
docs/navigation-configuration.md Outdated Show resolved Hide resolved
bszwarc and others added 2 commits January 10, 2019 14:36
Co-Authored-By: parostatkiem <jansudczak@gmail.com>
Co-Authored-By: parostatkiem <jansudczak@gmail.com>
Copy link
Contributor

@maxmarkus maxmarkus left a comment

Choose a reason for hiding this comment

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

LGTM

@kwiatekus kwiatekus merged commit d7d43a1 into SAP:master Jan 14, 2019
@parostatkiem-zz parostatkiem-zz deleted the improve-404-handling branch February 5, 2019 08:27
stanleychh pushed a commit to stanleychh/luigi that referenced this pull request Dec 30, 2021
Improve 404 handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants