-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
980325d
commit 0d68b3c
Showing
9 changed files
with
200 additions
and
238 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import "dotenv/config"; | ||
import 'express-async-errors' | ||
import env from "./config/envConfig"; | ||
import express from "express"; | ||
import redis from "./database/redis"; | ||
|
||
import currencyRoutes from "./routes/currencyRoute"; | ||
import errorMiddleware from "./middlewares/error"; | ||
|
||
redis.connect(); | ||
|
||
const app = express(); | ||
|
||
app.use(express.json()); | ||
|
||
app.use(currencyRoutes); | ||
app.use(errorMiddleware) | ||
|
||
app.listen(env.PORT, () => console.log(`Server running on port ${env.PORT}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
import { ApiError } from "../utils/apiError"; | ||
|
||
export default function errorMiddleware( | ||
error: Error & Partial<ApiError>, | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) { | ||
const statusCode = error.statusCode ?? 500; | ||
const message = | ||
statusCode === 500 ? "Internal server error" : error.message; | ||
res.status(statusCode).json({ message }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.