Skip to content

Commit 1873ef3

Browse files
committed
removed 404 page in lieu of json error response + set gloabl json content type
1 parent bbbee10 commit 1873ef3

File tree

3 files changed

+9
-65
lines changed

3 files changed

+9
-65
lines changed

app.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const compression = require("compression")
66
const helmet = require("helmet")
77
const config = require("./config.json")
88
const MongoClient = require("mongodb")
9-
const Path = require("path")
109
const app = express()
1110

1211
const home = require("./routes/v1-home")
@@ -30,9 +29,15 @@ app.use("/v1/launches", launches)
3029
app.use("/v1/launches/upcoming", upcoming)
3130
app.use("/v1/parts", parts)
3231

32+
// Global content type
33+
app.use((req, res, next) => {
34+
res.header("Content-Type","application/json")
35+
next()
36+
})
37+
3338
// 404 Error Handler
3439
app.use((req, res) => {
35-
res.status(404).sendFile(Path.join(__dirname + "/pages/404.html"))
40+
res.status(404).json("No Endpoint Found")
3641
})
3742

3843
MongoClient.connect(config.url, (err, database) => {

pages/404.html

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/v1-all.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ beforeAll((done) => {
1212
// 404 Page
1313
//------------------------------------------------------------
1414

15-
test("It should return 404 page", () => {
15+
test("It should return 404 endpoint error", () => {
1616
return request(app).get("/v2").then(response => {
1717
expect(response.statusCode).toBe(404)
18+
expect(response.text).toContain("No Endpoint Found")
1819
})
1920
})
2021

0 commit comments

Comments
 (0)