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

MagentoRouteHandler: correct handling of unknown routes #1495

Merged
merged 5 commits into from Aug 12, 2019

Conversation

niklaswolf
Copy link
Contributor

@niklaswolf niklaswolf commented Jul 30, 2019

Description

MagentoRouteHandler now correctly returns NotFound if the urlResolver-Query returns null.
Further description see issue #1454

Related Issue

Closes #1454 .

Verification Steps

  1. Edit RootComponents/CMS/cms.js:
import React, {Component, Fragment} from 'react';
import CategoryList from '../../components/CategoryList';
import {Link} from "react-router-dom";

export default class CMS extends Component {
    render() {
        return <Fragment>
            <CategoryList title="Shop by category" id={2} />
            <Link to={'/junk.html'}>Click me</Link>
        </Fragment>;
    }
}
  1. Click the link in Venia
  2. See that the error message reads "That page could not be found. Please try again." instead of "Something went wrong. Please try again."

Proposed Labels for Change Type/Package

  • major (e.g x.0.0 - a breaking change)
  • minor (e.g 0.x.0 - a backwards compatible addition)
  • patch (e.g 0.0.x - a bug fix)

Checklist:

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@magento-cicd2
Copy link

magento-cicd2 commented Jul 30, 2019

CLA assistant check
All committers have signed the CLA.

@vercel
Copy link

vercel bot commented Jul 30, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://pwa-studio-git-fork-mothership-gmbh-1451-magentoroutehandler.mmansoor.now.sh

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jul 30, 2019

Messages
📖 We are currently working on automating the PR metadata checks. Until that time, you may see failures related to labels/description/linked issues/etc even if you have fixed the problem. Failures will persist until the next push (assuming they are fixed).

Generated by 🚫 dangerJS against 2fa41c5

@zetlen zetlen self-requested a review August 5, 2019 15:56
@supernova-at supernova-at self-assigned this Aug 6, 2019
Copy link
Contributor

@supernova-at supernova-at left a comment

Choose a reason for hiding this comment

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

Code change is nice and concise, and thanks for adding a unit test!

Could you please provide some verification steps though?

Admittedly I'm new to this code but when I navigate to a route that doesn't exist (/junk.html) I do get a the 404 treatment:

Screen Shot 2019-08-06 at 11 40 12 AM

Here it is against the latest develop: https://magento-venia-develop.now.sh/junk.html

When I navigate to /junk (without the .html), I get a much worse un-styled error message:

Not Found

Here that is agains the latest develop: https://magento-venia-develop.now.sh/junk.

@niklaswolf
Copy link
Contributor Author

@supernova-at You don't see this error in these cases, because you do initial requests. The initial requests get resolved directly in the upward server, so you get the "not found" shell.

Only non-initial route changes get processed by the magento route handler (see linked issue #1454 ). So to force this error, you'd have to include a broken route link somewhere into the app, e.g. I included a broken link on the home page
RootComponents/CMS/cms.js

import React, {Component, Fragment} from 'react';
import CategoryList from '../../components/CategoryList';
import {Link} from "react-router-dom";

export default class CMS extends Component {
    render() {
        return <Fragment>
            <CategoryList title="Shop by category" id={2} />
            <Link to={'/junk.html'}>Click me</Link>
        </Fragment>;
    }
}

When you click the link, you'll now see a 404 "That page could not be found. Please try again." from the ErrorView component. Without the changes, it's a 500 "Something went wrong. Please try again."

Hit me up when you have further issues testing (I'm also available in the community slack ;))

Copy link
Contributor

@zetlen zetlen left a comment

Choose a reason for hiding this comment

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

I'm almost 100% sure this is great, and thank you for contributing. Just had one question.

@@ -94,8 +94,12 @@ export default class MagentoRouteHandler extends Component {
route: pathname
});

const { type, id } = resolvedRoute;
// urlResolver query returns null if a route can't be found
if (resolvedRoute === null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to rely on a literal null, and I'm not sure that's guaranteed. Any reason not to just test it for truthiness here?

Copy link
Contributor Author

@niklaswolf niklaswolf Aug 8, 2019

Choose a reason for hiding this comment

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

@zetlen In all of my tests null was returned, if there was no match, that's why I decided to make it rely on literal null. And I wanted to have these changes as unobstrusive as possible. But I'm also fine with just checking for truthiness. Should I change this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, would you mind?

Suggested change
if (resolvedRoute === null) {
if (!resolvedRoute) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zetlen Applied your suggested change

@VladimirZaets VladimirZaets added this to Work in Progress in Pull Request Progress Aug 8, 2019
@m2-community-project m2-community-project bot moved this from Work in Progress to Review in Progress in Pull Request Progress Aug 8, 2019
@supernova-at supernova-at added the version: Patch This changeset includes backwards compatible bug fixes. label Aug 8, 2019
supernova-at
supernova-at previously approved these changes Aug 8, 2019
Copy link
Contributor

@supernova-at supernova-at 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 - thank you!

@m2-community-project m2-community-project bot moved this from Review in Progress to Ready for Review in Pull Request Progress Aug 12, 2019
@m2-community-project m2-community-project bot moved this from Ready for Review to Reviewer Approved in Pull Request Progress Aug 12, 2019
@zetlen zetlen merged commit 0fc7c25 into magento:develop Aug 12, 2019
@m2-community-project m2-community-project bot moved this from Reviewer Approved to Done in Pull Request Progress Aug 12, 2019
@niklaswolf niklaswolf deleted the 1451-magentoRouteHandler branch August 13, 2019 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:peregrine version: Patch This changeset includes backwards compatible bug fixes.
Development

Successfully merging this pull request may close these issues.

[bug]: MagentoRouteHandler gives InternalError instead of NotFound (404)
6 participants