Skip to content

Commit 32cafcb

Browse files
kevinccbsgBetisman
andauthored
[chore] Add typescript support (#16)
* 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 <[email protected]> * Update examples/ts-example/tsconfig.json Co-authored-by: Carlos Jiménez <[email protected]> * featÃ: update pr feedback * chore: bump version to 1.0.7 Co-authored-by: Carlos Jiménez <[email protected]>
1 parent 0011b15 commit 32cafcb

File tree

8 files changed

+10715
-11
lines changed

8 files changed

+10715
-11
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
examples

examples/ts-example/app.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import express, { Express } from 'express';
2+
import winston from 'winston';
3+
import {
4+
CustomErrorTypes,
5+
errorFactory,
6+
handleHttpError,
7+
tagError,
8+
} from '../..';
9+
10+
const logger = winston.createLogger({
11+
level: 'info',
12+
format: winston.format.json(),
13+
defaultMeta: { service: 'user-service' },
14+
transports: [
15+
//
16+
// - Write all logs with importance level of `error` or less to `error.log`
17+
// - Write all logs with importance level of `info` or less to `combined.log`
18+
//
19+
new winston.transports.File({ filename: 'error.log', level: 'error' }),
20+
new winston.transports.File({ filename: 'combined.log' }),
21+
],
22+
});
23+
24+
const PORT = process.env.PORT || 4000;
25+
const wrongInputError = errorFactory(CustomErrorTypes.BAD_REQUEST);
26+
27+
const app: Express = express();
28+
29+
app.get('/api', (_req, _res, next) => {
30+
try {
31+
throw wrongInputError('Wrong Input message', { extraInfo: 'Extra info' });
32+
} catch (error) {
33+
return next(tagError(error));
34+
}
35+
});
36+
app.use(handleHttpError(logger));
37+
38+
app.listen(PORT, () =>
39+
console.log(`Listening PORT: ${PORT}`)
40+
);

0 commit comments

Comments
 (0)