Skip to content

Commit bc6c614

Browse files
committed
Add route not found and default message for QuestionService API
1 parent 6368983 commit bc6c614

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Backend/QuestionService/app.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,27 @@ mongoose.connect(mongoURI)
1717

1818
app.use('/api/questions', questionRouter)
1919

20+
app.get("/", (req, res, next) => {
21+
console.log("Sending Greetings!");
22+
res.json({
23+
message: "Hello World from question-service",
24+
});
25+
});
26+
27+
// Handle When No Route Match Is Found
28+
app.use((req, res, next) => {
29+
const error = new Error("Route Not Found");
30+
error.status = 404;
31+
next(error);
32+
});
33+
34+
app.use((error, req, res, next) => {
35+
res.status(error.status || 500);
36+
res.json({
37+
error: {
38+
message: error.message,
39+
},
40+
});
41+
});
42+
2043
module.exports = app

0 commit comments

Comments
 (0)