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

updates #487 - update pages routes #485

Merged
merged 5 commits into from
Feb 10, 2021

Conversation

Ulisseus
Copy link
Collaborator

@Ulisseus Ulisseus commented Feb 2, 2021

#484 needs to be merged first. Part of #467.

This PR updates page routes. If user is unauthorized he will be redirected to login page. If the page does not exist he will get 404 Error. Graphql error will result in 500 Internal Server Error.

@vercel
Copy link

vercel bot commented Feb 2, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/c0d3/c0d3-app/q5tumk81w
✅ Preview: https://c0d3-app-git-fork-ulisseus-error-routes.c0d3.vercel.app

@codecov
Copy link

codecov bot commented Feb 2, 2021

Codecov Report

Merging #485 (3b8c9a4) into master (0702205) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #485   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           97        97           
  Lines         1342      1355   +13     
  Branches       290       294    +4     
=========================================
+ Hits          1342      1355   +13     
Impacted Files Coverage Δ
containers/withQueryLoader.tsx 100.00% <100.00%> (ø)
pages/curriculum.tsx 100.00% <100.00%> (ø)
pages/curriculum/[lesson].tsx 100.00% <100.00%> (ø)
pages/profile/[username].tsx 100.00% <100.00%> (ø)

@@ -12,7 +12,7 @@ export type User = {
}

export type Lesson = {
id: number
id: string
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See #486. Such small change doesn't warrant a separate PR.

pages/404.tsx Outdated
export default function NotFound() {
return <Error statusCode={404} />
return <Error title="404 error" src="/404.png" message="Page not found" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Next.JS has a default 404 page. Please utilize this instead of creating a 404 page.

Copy link
Collaborator Author

@Ulisseus Ulisseus Feb 4, 2021

Choose a reason for hiding this comment

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

I don't understand, according to docs next.js suggests editing pages/404.tsx to create a custom error page. Do you want me to modify next.js error component instead of creating my own?

Copy link
Collaborator

@hwong0305 hwong0305 Feb 7, 2021

Choose a reason for hiding this comment

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

You're right. I thought next.js uses a different syntax than 404 for page. That part is fine.

However, it's better to override next.js error component rather than creating a 500 page. Otherwise, users won't be redirected to 404 when they go to c0d3.com/500 for whatever reason.

Copy link
Collaborator Author

@Ulisseus Ulisseus Feb 8, 2021

Choose a reason for hiding this comment

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

Otherwise, users won't be redirected to 404 when they go to c0d3.com/500 for whatever reason.

c0d3.com/500 won't redirect to 404 page (check vercel), but you're right, I forgot to update _error page. I edited it and it should display new Error screens too.

pages/500.tsx Outdated
import React from 'react'
import Error from '../components/Error'

export default function NotFound() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A status code of 500 is a server error and isn't not found. This function name is misleading.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks reasonable, will be fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

}
if (!lessons || !alerts) {
return (
<Error title="Internal server error" message="Bad data" src="/500.png" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this mean the user is not logged in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No session means that user is not logged in. This case happens if there is a session but no lessons or no alerts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it better to redirect to login if this is the case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it would be more confusing. Since there is nothing wrong with session already authorized user could be redirected to login page. He relogins, login redirects him to curriculum page, no lessons/alerts, he is on log in page again.
This way he'll get a 500 error screen and won't waste time logging in/logging out.

)
if (!currentLesson) {
return <Error title="404 error" message="Page not found" src="/404.png" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

404 should be reserved for the page is not found. Not an error.

Copy link
Collaborator Author

@Ulisseus Ulisseus Feb 4, 2021

Choose a reason for hiding this comment

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

This case happens if user tries to open lessonID which does not exist, something like https://www.c0d3.com/curriculum/100ShouldNotExist. I could redirect him to 404 page but this way he won't be able to check his incorrect url since it's instantly replaced by c0d3/404.
Do you want me to rename Error component for something else?

Copy link
Collaborator

@hwong0305 hwong0305 left a comment

Choose a reason for hiding this comment

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

See comments in PR.

Copy link
Collaborator

@hwong0305 hwong0305 left a comment

Choose a reason for hiding this comment

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

Updating my comment to amend the point on the 404 page.

@hwong0305 hwong0305 dismissed their stale review February 7, 2021 08:49

Updating it to just a comment.

pages/_error.tsx Outdated
const statusCode = res ? res.statusCode : err ? err.statusCode : 404
const errorInitialProps = {
statusCode,
hasGetInitialPropsRun: false
Copy link
Collaborator

Choose a reason for hiding this comment

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

On line 40, you set this value to true. So it's redundant here

@ggwadera ggwadera changed the title update pages routes updates #487 - update pages routes Feb 10, 2021
@ggwadera ggwadera merged commit 043ad16 into garageScript:master Feb 10, 2021
@Ulisseus Ulisseus deleted the Error/routes branch March 5, 2021 19:30
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.

5 participants