Skip to content

Instantly share code, notes, and snippets.

@seanpmaxwell
Last active May 29, 2019 05:19
Show Gist options
  • Save seanpmaxwell/a1be076cbedfc35ba932eccacde1db36 to your computer and use it in GitHub Desktop.
Save seanpmaxwell/a1be076cbedfc35ba932eccacde1db36 to your computer and use it in GitHub Desktop.
TypeScriptFullStackShell/src/controllers/demo/DemoController.ts
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