Skip to content

Commit

Permalink
[chore] Add typescript support (#16)
Browse files Browse the repository at this point in the history
* chore: update dependencies and include express types

* feat: add library types

* docs: add examples and eslintignore for these examples

* Update .eslintignore

Co-authored-by: Carlos Jiménez <betisman@gmail.com>

* Update examples/ts-example/tsconfig.json

Co-authored-by: Carlos Jiménez <betisman@gmail.com>

* featÃ: update pr feedback

* chore: bump version to 1.0.7

Co-authored-by: Carlos Jiménez <betisman@gmail.com>
  • Loading branch information
kevinccbsg and Betisman committed Sep 22, 2022
1 parent 0011b15 commit 32cafcb
Show file tree
Hide file tree
Showing 8 changed files with 10,715 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
40 changes: 40 additions & 0 deletions examples/ts-example/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import express, { Express } from 'express';
import winston from 'winston';
import {
CustomErrorTypes,
errorFactory,
handleHttpError,
tagError,
} from '../..';

const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'user-service' },
transports: [
//
// - Write all logs with importance level of `error` or less to `error.log`
// - Write all logs with importance level of `info` or less to `combined.log`
//
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' }),
],
});

const PORT = process.env.PORT || 4000;
const wrongInputError = errorFactory(CustomErrorTypes.BAD_REQUEST);

const app: Express = express();

app.get('/api', (_req, _res, next) => {
try {
throw wrongInputError('Wrong Input message', { extraInfo: 'Extra info' });
} catch (error) {
return next(tagError(error));
}
});
app.use(handleHttpError(logger));

app.listen(PORT, () =>
console.log(`Listening PORT: ${PORT}`)
);
Loading

0 comments on commit 32cafcb

Please sign in to comment.