Skip to content

Commit

Permalink
Merge pull request Open-Source-Chandigarh#95 from Ani1702/issue-48-fix
Browse files Browse the repository at this point in the history
Resolved issue Open-Source-Chandigarh#48: Added a custom error page
  • Loading branch information
Aryainguz authored May 15, 2024
2 parents 3a8b000 + b60e59f commit baf4248
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
./DS_Store
node_modules/
12 changes: 11 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require("express")
const bodyParser = require("body-parser")
const axios = require("axios")
const sgMail = require("@sendgrid/mail")
const ExpressError=require("./utils/ExpressError.js")

require("dotenv").config()

Expand Down Expand Up @@ -84,4 +85,13 @@ app.post("/result",async (req,res)=>{

app.listen(process.env.PORT || 3000,function(){
console.log("Server Started Sucessfully")
})
})

app.all("*",(req,res,next)=>{
next(new ExpressError(404,"Page not found!"));
});

app.use((err,req,res,next)=>{
let {statusCode=500,message="Something Went Wrong"}=err;
res.render("customError.ejs",{message});
});
7 changes: 7 additions & 0 deletions utils/ExpressError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports=class ExpressError extends Error{
constructor(statusCode,message){
super();
this.statusCode=statusCode;
this.message=message;
}
}
12 changes: 12 additions & 0 deletions views/customError.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Invalid</title>
</head>
<body>
<h3 style="font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; color: red;"><%= message %></h3>
<a href="/"><button>Home</button></a>
</body>
</html>

0 comments on commit baf4248

Please sign in to comment.