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

adds: error page front-end concept #925

Merged
merged 5 commits into from
Apr 16, 2020

Conversation

raygervais
Copy link
Contributor

@raygervais raygervais commented Apr 3, 2020

Issue This PR Addresses

Fixes #890

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

This adds a catch-all route at the end of the routes declaration which redirects to our (WIP) 40X page component. Will add appropriate 50x page as well.

How To Access

From a fully deployed Docker-compose environment, attempt any url which you'd fat-finger by accident at 3am. This will redirect back to the front-end with the appropriate error response. Example, entering localhost:3000/AWorldWhereWindowsWins should redirect straight to localhost:3000/error?status=404 as seen below.

Checklist

  • Quality: This PR builds and passes our npm test and works locally

  • Tests: This PR includes thorough tests or an explanation of why it does not

  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)
    image

  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

@raygervais
Copy link
Contributor Author

@cindyledev, @humphd, @agarcia-caicedo, looking for your input on how we should style and layout the 40X / 50X error pages. For the above, just to prove the concept I reused Banner layout styling. Was contemplating adding the banner (sans banner text) in the background.

PR is still WIP, looking for input and feedback.

@raygervais
Copy link
Contributor Author

raygervais commented Apr 3, 2020

Because of the Zeit setup, you won't be able to follow the instructions first step (attempting to access any non-standard URL) and instead can test with this URL (which is the redirect): https://telescope-mxr4bagfx.now.sh/error?status=<PUT_WHATEVER_STATUS_YOUD_LIKE>. Locally, this works end-to-end.

@cindyorangis
Copy link
Contributor

cindyorangis commented Apr 3, 2020

Tested on Zeit, I like where this is going. Unfortunately, this seems to be suffering from the css bug #841 #741 . We have at least 3 PRs open that are affected by it

@cindyorangis
Copy link
Contributor

Also tested on Linux
Screenshot from 2020-04-03 22-18-24

* 404 Handler, Pass to front-end
* Leverage .status because adding the `404` status in redirect causes "Not Found. Redirecting to /404?search=" to display.
*/
router.use('*', (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The way this is usually done is as error handling middleware at the end of the routing chain, with an extra error handler at the end:

// Last in the chain
app.use(function (req, res, next) {
  res.status(404).send('...');
});

// Error handling middleware
app.use(function (err, req, res, next) {
  logger.error({ error: err }, 'express web server error');
  res.status(500).send('...')
});

const originalUrl = req.originalUrl.trim();
res
.status(404)
.redirect(`/404?search=${originalUrl}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

You better encodeURIComponent() this originalUrl

res
.status(404)
.redirect(`/404?search=${originalUrl}`)
.sendFile(path.join(__dirname, '../../../frontend/public/index.html'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why redirect and send this file? Would you not just redirect?

const params = new URLSearchParams(props.location.search);
let originalUrl = params
.get('search')
?.replace('/', '')
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what this is doing. I'm also not sure that we should introduce ?. to our code base without discussing implications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ?. is the new optional chaining operator, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

It's essentially a replacement of the following semantic:

const a= params.get('search');
 if (a) {
    const b = a.replace('/', '');

   if (b) {
     const c = b.match(....);

     ... and so on
   }
 }

The reason for the actual functions is removing the / at the start of the URL search param, which I may be able to remove with the urlEncode that you suggested above. Furthermore, it formats the param client-side to Capital Spaced if capital letters exist. Can remove, thought it was a nice little addon.

src/frontend/src/pages/404.jsx Outdated Show resolved Hide resolved
src/frontend/src/pages/404.jsx Outdated Show resolved Hide resolved
Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

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

This is looking amazing. I'm not sure about the purple colour you're introducing (cc @agarcia-caicedo). I left some initial comments in the code.

},
}));

function RetrieveBackgroundAsset() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this repeated code? Can we refactor this out into a separate component?

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 like to refactor into a separate component in this PR, is that alright? Or separate follow-up?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is fine, nothing is depending on this for timing.

const classes = useStyles();

return (
<PageBase title="404">
Copy link
Contributor

Choose a reason for hiding this comment

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

Either here or in follow-up, I'd love to generalize this page so that it works for 403s (forbidden) and 500s (errors).

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 can do that here, keep all the scope around 40X and 50X pages starting here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great

src/backend/web/app.js Show resolved Hide resolved
@Silvyre Silvyre self-requested a review April 6, 2020 16:47
@agarcia-caicedo
Copy link
Contributor

This is looking amazing. I'm not sure about the purple colour you're introducing (cc @agarcia-caicedo). I left some initial comments in the code.

Can't say I'm a fan of the purple. I don't think it works aesthetically, and since it's the only place we've used it, it looks out of place

@cindyorangis
Copy link
Contributor

I'm digging this so far but I'm not too sure about the purple back button. @agarcia-caicedo , what are your thoughts?
Annotation 2020-04-10 233857

fixes: rebase and component cleanup

reverts: colors back to secondary base

adds: authenticaton 403 concept and 500 wip
Copy link
Contributor

@Silvyre Silvyre left a comment

Choose a reason for hiding this comment

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

Navigating to /404 (which is currently where My Feeds sends unauthorized users to) is still rendering the "Gatsby.js development 404 page" for me:
image

(HTML of Gatsby.js 404 page)

Gatsby.js development 404 page

There's not a page yet at /404

Preview custom 404 page

Create a React.js component in your site directory at src/pages/404.js and this page will automatically refresh to show the new page component you created.

If you were trying to reach another page, perhaps you can find it below.

Pages (6)

Search:

Is this intended behaviour; should I update the My Feeds to redirect users to somewhere else?

@raygervais
Copy link
Contributor Author

This is because we don't have a custom 404 page, instead I'm using /error as a wrapper for both. I'd redirect there, or in a follow up PR I create a 404 which is a wrapper around error.

@raygervais
Copy link
Contributor Author

You should be sending to 403, since they are not authorized @Silvyre. /error?status=403

@Silvyre
Copy link
Contributor

Silvyre commented Apr 15, 2020

I'm using /error as a wrapper for both. I'd redirect there, or in a follow up PR I create a 404 which is a wrapper around error.

Okay, cool: redirecting to /error?status=403 seems to work well. We could alternatively have the My Feeds page redirect logged-out users to the login page (which I recall is what @humphd may have suggested this morning). I filed an issue (#1016) to implement this.


A few other things...

Navigating to http://localhost:3000/error (without a query string) presents:
image

Do you think it would be worth populating the blank card here with the "Something went wrong!" text?

Also, I noticed that navigating to http://localhost:3000/error?status=40X renders the numerical status code (e.g. "40X") within the page title, which is really cool:
image

Do you think it would be worthwhile to add a switch that replaces some numerical status codes with their common names? e.g. being redirected to http://localhost:3000/error?status=404 would result in a page title of "Not Found | Telescope" instead of "404 | Telescope", etc. Ultimately up to you!

Lastly, I'm not sure whether this next issue affects only my own machine/browser, but when I navigate to a page like http://localhost:3000/error?status=404, the card/button component appears to have some margin issues:
image

This does not happen when I decrease the size of my browser window to a size breakpoint smaller:
image


Thanks for all of your hard work on this! 👍

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

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

One more thing I notice, then this is good from my end.

src/backend/web/authentication.js Show resolved Hide resolved
@raygervais
Copy link
Contributor Author

Thanks for testing so vigorously @Silvyre, that edge (where the user stumbles onto the page) I never thought of. Corrected in upcoming commit.

image

humphd
humphd previously approved these changes Apr 16, 2020
Grommers00
Grommers00 previously approved these changes Apr 16, 2020
@raygervais
Copy link
Contributor Author

raygervais commented Apr 16, 2020

@Silvyre can I get a re-review?

@Silvyre Silvyre self-requested a review April 16, 2020 04:49
Copy link
Contributor

@cindyorangis cindyorangis left a comment

Choose a reason for hiding this comment

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

I have some small nits in error.jsx:

  • instead of importing on multiple lines
import Typography from '@material-ui/core/Typography';
import { Fab } from '@material-ui/core';
import Grid from '@material-ui/core/Grid';
import Card from '@material-ui/core/Card';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';

write it in one line import { Card, CardActions, CardContent, Fab, Grid, Typography } from '@material-ui/core';

  • eslint doesn't seem to like that you import PageBase from './PageBase' before all the @material-ui stuff
  • import DynamicBackgroundContainer from '../components/DynamicBackgroundContainer';, eslint wants the .jsx extension (also used in Banner.jsx)
  • In Fixes #1002: fixes JSX-related issues in Banner.jsx, Posts.jsx #1006 we removed <ThemeProvider> since it didn't really do anything. Should be done here as well.

Other than these little things, the rest look great :D

Silvyre
Silvyre previously approved these changes Apr 16, 2020
Copy link
Contributor

@Silvyre Silvyre left a comment

Choose a reason for hiding this comment

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

Quite happy to push this on through! 👍

adds: corrections based on circleCI and SSR requirements
@raygervais
Copy link
Contributor Author

Thanks for the corrections @cindyledev, can I get a re-review when you have a moment? So Happy to have the eslint warnings gone! 🎆

@raygervais raygervais removed the request for review from agarcia-caicedo April 16, 2020 15:31
@raygervais raygervais merged commit 46441e0 into Seneca-CDOT:master Apr 16, 2020
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.

Create custom pages for HTTP 404, 403, 500s
6 participants