-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Improvement of error handling and logging
- Loading branch information
Showing
22 changed files
with
168 additions
and
61 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
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
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
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
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
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
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
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
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
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
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,26 @@ | ||
export class JournalError extends Error { | ||
constructor(message: string, options?: ErrorOptions) { | ||
super(message, options) | ||
} | ||
} | ||
|
||
// HTTP 400 | ||
export class BadRequestError extends JournalError { | ||
constructor(message: string, options?: ErrorOptions) { | ||
super(message, options) | ||
} | ||
} | ||
|
||
// HTTP 404 | ||
export class NotFoundError extends JournalError { | ||
constructor(message: string, options?: ErrorOptions) { | ||
super(message, options) | ||
} | ||
} | ||
|
||
// HTTP 422 | ||
export class UnprocessableEntityError extends JournalError { | ||
constructor(message: string, options?: ErrorOptions) { | ||
super(message, options) | ||
} | ||
} |
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 @@ | ||
export * from './errors' |
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
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 |
---|---|---|
@@ -1,22 +1,34 @@ | ||
import pino from 'pino' | ||
import pino, { Logger } from 'pino' | ||
|
||
const isProduction = process.env.NODE_ENV === 'production' | ||
const isTest = process.env.NODE_ENV === 'test' | ||
|
||
const logger = pino({ | ||
name: 'main', | ||
nestedKey: 'payload', | ||
level: process.env.LOG_LEVEL || 'info', | ||
browser: { | ||
asObject: true, | ||
disabled: ['production'].includes(process.env.NODE_ENV) === true | ||
disabled: isProduction | ||
}, | ||
transport: | ||
['production'].includes(process.env.NODE_ENV) === false | ||
? { | ||
target: 'pino-pretty', | ||
options: { | ||
colorize: true, | ||
translateTime: 'SYS:standard', | ||
ignore: 'pid,hostname' | ||
} | ||
transport: !isProduction | ||
? { | ||
target: 'pino-pretty', | ||
options: { | ||
colorize: true, | ||
translateTime: 'SYS:standard', | ||
ignore: 'pid,hostname' | ||
} | ||
: undefined, | ||
enabled: ['test'].includes(process.env.NODE_ENV) === false | ||
} | ||
: undefined, | ||
enabled: !isTest | ||
}) | ||
|
||
export const createContextLogger = (name: string, context?: Logger) => { | ||
if (!context) { | ||
return logger.child({ name }) | ||
} | ||
return context.child({}, { msgPrefix: name }) | ||
} | ||
|
||
export default logger |
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
Oops, something went wrong.