Skip to content

Commit

Permalink
.....
Browse files Browse the repository at this point in the history
  • Loading branch information
WeStOn2000 committed Jul 18, 2024
1 parent 2dfed37 commit 14eaf16
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dependency directories
node_modules/

# MacOS files
.DS_Store
10 changes: 7 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ app.get('/projects/:id', (req, res) => {
*/
// 404 Handler
app.use((req, res, next) => {
const err = new Error('Not Found');
const err = new Error('Sorry this Page is Not Found');
err.status = 404;
res.render('error');
next(err);
});
// Global Error Handler
app.use((err, req, res, next) => {

console.log(`Error Status: ${err.status || 500}`);
console.log(`Error Message: ${err.message}`);
res.status(err.status|| 500);
res.render('error',{
message: err.message,
res.render('page not found',{
message: "Oops Unfortunately We are unable to locate this page!!!",
error: {}
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "project",
"version": "1.0.0",
"main": "index.js",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
21 changes: 14 additions & 7 deletions views/error.pug
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
doctype html
html
head
title Error
body
h1 Error #{status}
p #{message}
extend layout

block content


h1 Error #{status}
p #{message}


if status !== 404 && error.stack
pre #{error.stack}


a(href='/') Back to Home
10 changes: 10 additions & 0 deletions views/page not found.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extend layout

block content


h1 Error #{status}: #{message}
p The page you are looking for does not exist.


a(href='/') Back to Home

0 comments on commit 14eaf16

Please sign in to comment.