-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.ts
30 lines (27 loc) · 939 Bytes
/
controller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { OK, BAD_REQUEST } from "http-status-codes";
import { Controller, Get } from "@overnightjs/core";
import { Logger } from "@overnightjs/logger";
import { Request, Response } from "express";
@Controller("api/my-sample-react-app")
class MySampleController {
public static readonly MSG = "hello ";
@Get(":api_name")
private sayHello(req: Request, res: Response) {
try {
const { api_name } = req.params;
if (api_name === "error-api") {
throw Error("There was some failure!");
}
Logger.Info(MySampleController.MSG + name);
return res.status(OK).json({
message: MySampleController.MSG + name,
});
} catch (err) {
Logger.Err(err, true);
return res.status(BAD_REQUEST).json({
error: err.message,
});
}
}
}
export default MySampleController;