-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 <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
1 parent
0011b15
commit 32cafcb
Showing
8 changed files
with
10,715 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
examples |
This file contains 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
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}`) | ||
); |
Oops, something went wrong.