Last active
May 29, 2019 05:19
-
-
Save seanpmaxwell/a1be076cbedfc35ba932eccacde1db36 to your computer and use it in GitHub Desktop.
TypeScriptFullStackShell/src/controllers/demo/DemoController.ts
This file contains hidden or 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
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/say-hello') | |
class DemoController { | |
public static readonly SUCCESS_MSG = 'hello '; | |
@Get(':name') | |
private sayHello(req: Request, res: Response) { | |
try { | |
const { name } = req.params; | |
if (name === 'make_it_fail') { | |
throw Error('User triggered failure'); | |
} | |
Logger.Info(DemoController.SUCCESS_MSG + name); | |
return res.status(OK).json({ | |
message: DemoController.SUCCESS_MSG + name, | |
}); | |
} catch (err) { | |
Logger.Err(err, true); | |
return res.status(BAD_REQUEST).json({ | |
error: err.message, | |
}); | |
} | |
} | |
} | |
export default DemoController; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment