-
Notifications
You must be signed in to change notification settings - Fork 189
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
Conversation
@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. |
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): |
src/backend/web/routes/index.js
Outdated
* 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) => { |
There was a problem hiding this comment.
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('...')
});
src/backend/web/routes/index.js
Outdated
const originalUrl = req.originalUrl.trim(); | ||
res | ||
.status(404) | ||
.redirect(`/404?search=${originalUrl}`) |
There was a problem hiding this comment.
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
src/backend/web/routes/index.js
Outdated
res | ||
.status(404) | ||
.redirect(`/404?search=${originalUrl}`) | ||
.sendFile(path.join(__dirname, '../../../frontend/public/index.html')); |
There was a problem hiding this comment.
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?
src/frontend/src/pages/404.jsx
Outdated
const params = new URLSearchParams(props.location.search); | ||
let originalUrl = params | ||
.get('search') | ||
?.replace('/', '') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
src/frontend/src/pages/404.jsx
Outdated
}, | ||
})); | ||
|
||
function RetrieveBackgroundAsset() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/frontend/src/pages/404.jsx
Outdated
const classes = useStyles(); | ||
|
||
return ( | ||
<PageBase title="404"> |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great
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 |
I'm digging this so far but I'm not too sure about the purple back button. @agarcia-caicedo , what are your thoughts? |
fixes: rebase and component cleanup reverts: colors back to secondary base adds: authenticaton 403 concept and 500 wip
There was a problem hiding this 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:
(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.
Is this intended behaviour; should I update the My Feeds to redirect users to somewhere else?
This is because we don't have a custom 404 page, instead I'm using |
You should be sending to 403, since they are not authorized @Silvyre. |
Okay, cool: redirecting to A few other things... Navigating to Do you think it would be worth populating the blank card here with the "Something went wrong!" text? Also, I noticed that navigating to 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 Lastly, I'm not sure whether this next issue affects only my own machine/browser, but when I navigate to a page like This does not happen when I decrease the size of my browser window to a size breakpoint smaller: Thanks for all of your hard work on this! 👍 |
There was a problem hiding this 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.
Thanks for testing so vigorously @Silvyre, that edge (where the user stumbles onto the page) I never thought of. Corrected in upcoming commit. |
@Silvyre can I get a re-review? |
There was a problem hiding this 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 inBanner.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
There was a problem hiding this 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
3f98db7
Thanks for the corrections @cindyledev, can I get a re-review when you have a moment? So Happy to have the eslint warnings gone! 🎆 |
Issue This PR Addresses
Fixes #890
Type of Change
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 tolocalhost: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)
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)