Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

Commit 2dfb9e3

Browse files
committed
refactor: 📁 improve log readability
1 parent 869ba60 commit 2dfb9e3

File tree

21 files changed

+576
-584
lines changed

21 files changed

+576
-584
lines changed

apps/server/openapi3.json

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@
348348
"required": true,
349349
"in": "query",
350350
"description": "Email of created account to which verification email should be sent",
351-
"example": "Elfrieda_Jast@hotmail.com",
351+
"example": "Osborne_Wisoky5@hotmail.com",
352352
"schema": {
353353
"type": "string"
354354
}
@@ -635,7 +635,7 @@
635635
"email": {
636636
"type": "string",
637637
"description": "The account's email address",
638-
"example": "Elfrieda_Jast@hotmail.com",
638+
"example": "Osborne_Wisoky5@hotmail.com",
639639
"examples": [
640640
"Raul_Marks@gmail.com",
641641
"Buddy.Schulist@gmail.com",
@@ -655,11 +655,11 @@
655655
"username": {
656656
"type": "string",
657657
"description": "The account's username",
658-
"example": "Ronaldo.Ledner96",
658+
"example": "Trudie.Wolf",
659659
"examples": [
660-
"Herman.Bauch21",
661-
"Adolf_Schiller",
662-
"Lane.Braun-Raynor73"
660+
"Ricky.Herman5",
661+
"Elinore.Reichert",
662+
"Zelda_Bergstrom6"
663663
]
664664
}
665665
},
@@ -727,11 +727,11 @@
727727
"username": {
728728
"type": "string",
729729
"description": "The account's username",
730-
"example": "Ronaldo.Ledner96",
730+
"example": "Trudie.Wolf",
731731
"examples": [
732-
"Herman.Bauch21",
733-
"Adolf_Schiller",
734-
"Lane.Braun-Raynor73"
732+
"Ricky.Herman5",
733+
"Elinore.Reichert",
734+
"Zelda_Bergstrom6"
735735
]
736736
},
737737
"method": {
@@ -762,11 +762,11 @@
762762
"refreshToken": {
763763
"type": "string",
764764
"description": "...",
765-
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
765+
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDc2OTUzfQ.EfMor7c89EHcY3mtygp__7G9qp5qg2WMdruq8DofqJ8",
766766
"examples": [
767-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
768-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
769-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98"
767+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDc2OTUzfQ.EfMor7c89EHcY3mtygp__7G9qp5qg2WMdruq8DofqJ8",
768+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDc2OTUzfQ.EfMor7c89EHcY3mtygp__7G9qp5qg2WMdruq8DofqJ8",
769+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDc2OTUzfQ.EfMor7c89EHcY3mtygp__7G9qp5qg2WMdruq8DofqJ8"
770770
]
771771
}
772772
},
@@ -783,11 +783,11 @@
783783
"refreshToken": {
784784
"type": "string",
785785
"description": "...",
786-
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
786+
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDc2OTUzfQ.EfMor7c89EHcY3mtygp__7G9qp5qg2WMdruq8DofqJ8",
787787
"examples": [
788-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
789-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
790-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98"
788+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDc2OTUzfQ.EfMor7c89EHcY3mtygp__7G9qp5qg2WMdruq8DofqJ8",
789+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDc2OTUzfQ.EfMor7c89EHcY3mtygp__7G9qp5qg2WMdruq8DofqJ8",
790+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDc2OTUzfQ.EfMor7c89EHcY3mtygp__7G9qp5qg2WMdruq8DofqJ8"
791791
]
792792
}
793793
},
@@ -806,7 +806,7 @@
806806
"email": {
807807
"type": "string",
808808
"description": "The domain's email address",
809-
"example": "Elfrieda_Jast@hotmail.com",
809+
"example": "Osborne_Wisoky5@hotmail.com",
810810
"examples": [
811811
"Raul_Marks@gmail.com",
812812
"Buddy.Schulist@gmail.com",
@@ -816,16 +816,16 @@
816816
"emailVerified": {
817817
"type": "boolean",
818818
"description": "Indicates whether the email associated with a user domain has been verified",
819-
"example": false
819+
"example": true
820820
},
821821
"username": {
822822
"type": "string",
823823
"description": "The account's username",
824-
"example": "Ronaldo.Ledner96",
824+
"example": "Trudie.Wolf",
825825
"examples": [
826-
"Herman.Bauch21",
827-
"Adolf_Schiller",
828-
"Lane.Braun-Raynor73"
826+
"Ricky.Herman5",
827+
"Elinore.Reichert",
828+
"Zelda_Bergstrom6"
829829
]
830830
}
831831
},
@@ -843,11 +843,11 @@
843843
"username": {
844844
"type": "string",
845845
"description": "The account's username",
846-
"example": "Ronaldo.Ledner96",
846+
"example": "Trudie.Wolf",
847847
"examples": [
848-
"Herman.Bauch21",
849-
"Adolf_Schiller",
850-
"Lane.Braun-Raynor73"
848+
"Ricky.Herman5",
849+
"Elinore.Reichert",
850+
"Zelda_Bergstrom6"
851851
]
852852
},
853853
"password": {

apps/server/src/bootstrap.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import {Logger} from '@nestjs/common'
2-
import {NestFactory} from '@nestjs/core'
3-
import Sentry from '@sentry/node'
4-
import delay from 'delay'
5-
import type {NextFunction} from 'express'
6-
import ms from 'ms'
7-
import process from 'node:process'
8-
import {NestjsLogger} from "./common/logger/nestjs-logger-proxy.js"
9-
import {buildCompodocDocumentation} from './common/modules/documentation/compodoc/compodoc.js'
10-
import {buildSwaggerDocumentation} from './common/modules/documentation/swagger/swagger.js'
11-
import {executePrismaRelatedProcesses} from './common/modules/resources/prisma/utils/execute-prisma-related-processes.js'
1+
import {Logger} from '@nestjs/common'
2+
import {NestFactory} from '@nestjs/core'
3+
import Sentry from '@sentry/node'
4+
import delay from 'delay'
5+
import type {NextFunction} from 'express'
6+
import ms from 'ms'
7+
import process from 'node:process'
8+
import {HttpExceptionFilter} from "./common/filters/exception-filter/http-exception-filter.js"
9+
import {LoggerNestjsProxy} from "./common/logger/nestjs-logger-proxy.js"
10+
import {buildCompodocDocumentation} from './common/modules/documentation/compodoc/compodoc.js'
11+
import {buildSwaggerDocumentation} from './common/modules/documentation/swagger/swagger.js'
12+
import {executePrismaRelatedProcesses} from './common/modules/resources/prisma/utils/execute-prisma-related-processes.js'
1213
import {__appConfig, __config} from './configs/global/__config.js'
13-
import {isDevelopment} from './configs/helper/is-development.js'
14-
import {StaticFeatureFlags} from './configs/static-feature-flags.js'
15-
import {Container} from './container.js'
16-
import {migrateDatabase} from './hooks/post-start/migrate-database.js'
14+
import {isDevelopment} from './configs/helper/is-development.js'
15+
import {StaticFeatureFlags} from './configs/static-feature-flags.js'
16+
import {Container} from './container.js'
17+
import {migrateDatabase} from './hooks/post-start/migrate-database.js'
1718
import type {ExpressRequest, ExpressResponse} from './types/express-response.js'
18-
import {portAllocator} from './utilities/network-utils/port-allocator.js'
19+
import {portAllocator} from './utilities/network-utils/port-allocator.js'
1920

2021

2122

@@ -26,7 +27,7 @@ export async function bootstrap() {
2627
autoFlushLogs: true,
2728
bufferLogs: true,
2829
snapshot: isDevelopment(),
29-
logger: new NestjsLogger(),
30+
logger: new LoggerNestjsProxy(),
3031
})
3132

3233
// Implement logger used for bootstrapping and notifying about application state
@@ -52,7 +53,7 @@ export async function bootstrap() {
5253

5354
// The error handler must be before any other error middleware and after all controllers
5455
app.use(Sentry.Handlers.errorHandler())
55-
// app.useGlobalFilters( new HttpExceptionFilter() )
56+
app.useGlobalFilters(new HttpExceptionFilter())
5657

5758
// Optional fallthrough error handler
5859
app.use(function onError(_err: Error, _req: ExpressRequest, res: ExpressResponse, _next: NextFunction) {

apps/server/src/common/filters/exception-filter/http-exception-filter.ts

Lines changed: 53 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -23,95 +23,69 @@
2323
*
2424
*/
2525

26-
27-
import {
28-
ArgumentsHost,
29-
Catch,
30-
ExceptionFilter,
31-
HttpException,
32-
HttpStatus,
33-
Logger,
34-
} from '@nestjs/common'
35-
import { HttpArgumentsHost } from '@nestjs/common/interfaces'
36-
import {
37-
Request,
38-
Response,
39-
} from 'express'
40-
import {
41-
getCode,
42-
getErrorMessage,
43-
getObjectValue,
44-
} from './dirty-utilities.js'
26+
import {ArgumentsHost, Catch, ExceptionFilter, HttpException, HttpStatus, Logger} from '@nestjs/common'
27+
import {HttpArgumentsHost} from '@nestjs/common/interfaces'
28+
import {Request, Response} from 'express'
29+
import {getCode, getErrorMessage, getObjectValue} from './dirty-utilities.js'
4530

4631

4732

4833
/**
4934
* Catch and format thrown exception in NestJS application based on Express
5035
*/
5136
@Catch()
52-
export class HttpExceptionFilter
53-
implements ExceptionFilter
54-
{
55-
private readonly logger : Logger = new Logger( HttpExceptionFilter.name )
37+
export class HttpExceptionFilter implements ExceptionFilter {
38+
private readonly logger: Logger = new Logger(HttpExceptionFilter.name)
5639

57-
/**
58-
* Catch and format thrown exception
59-
*/
60-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
61-
public catch(
62-
exception : any,
63-
host : ArgumentsHost,
64-
) : void
65-
{
66-
const ctx : HttpArgumentsHost = host.switchToHttp()
67-
const request : Request = ctx.getRequest()
68-
const response : Response = ctx.getResponse()
69-
let status : number
7040

71-
if ( exception instanceof HttpException )
72-
{
73-
status = exception.getStatus()
74-
}
75-
else
76-
{
77-
// Case of a PayloadTooLarge
78-
const type : string | undefined = getObjectValue( exception, 'type' )
79-
status = type === 'entity.too.large' ? HttpStatus.PAYLOAD_TOO_LARGE
80-
: HttpStatus.INTERNAL_SERVER_ERROR
81-
}
41+
/**
42+
* Catch and format thrown exception
43+
*/
44+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
45+
public catch(exception: any, host: ArgumentsHost): void {
46+
const ctx: HttpArgumentsHost = host.switchToHttp()
47+
const request: Request = ctx.getRequest()
48+
const response: Response = ctx.getResponse()
49+
let status: number
8250

83-
let code : string = exception instanceof HttpException ? getCode( exception.getResponse() )
84-
: HttpStatus[ HttpStatus.INTERNAL_SERVER_ERROR ]
85-
let message : string = exception instanceof HttpException ? getErrorMessage( exception.getResponse() )
86-
: 'An internal server error occurred'
51+
if (exception instanceof HttpException) {
52+
status = exception.getStatus()
53+
} else {
54+
// Case of a PayloadTooLarge
55+
const type: string | undefined = getObjectValue(exception, 'type')
56+
status = type === 'entity.too.large' ?
57+
HttpStatus.PAYLOAD_TOO_LARGE :
58+
HttpStatus.INTERNAL_SERVER_ERROR
59+
}
8760

88-
if ( status === HttpStatus.PAYLOAD_TOO_LARGE )
89-
{
90-
code = HttpStatus[ HttpStatus.PAYLOAD_TOO_LARGE ]
91-
message = `
92-
Your request entity size is too big for the server to process it:
93-
- request size: ${getObjectValue( exception, 'length' )};
94-
- request limit: ${getObjectValue( exception, 'limit' )}.`
95-
}
96-
// const exceptionStack : string = 'stack' in exception ? exception.stack : ''
97-
if ( status >= HttpStatus.INTERNAL_SERVER_ERROR )
98-
{
99-
this.logger.error( `${status} [${request.method} ${request.url}] has thrown a critical error` )
100-
this.logger.error( `${JSON.stringify( exception )}` )
101-
}
102-
else if ( status >= HttpStatus.BAD_REQUEST )
103-
{
104-
this.logger.warn( `${status} [${request.method} ${request.url}] has thrown an HTTP client error` )
105-
this.logger.warn( `${JSON.stringify( exception )}` )
106-
// this.logger.warn( {
107-
// message : `${status} [${request.method} ${request.url}] has thrown an
108-
// HTTP client error`, exceptionStack, headers : request.headers, } )
109-
}
61+
let code: string = exception instanceof HttpException ?
62+
getCode(exception.getResponse()) :
63+
HttpStatus[HttpStatus.INTERNAL_SERVER_ERROR]
64+
let message: string = exception instanceof HttpException ?
65+
getErrorMessage(exception.getResponse()) :
66+
'An internal server error occurred'
11067

111-
response.status( status ).send( {
112-
code,
113-
message,
114-
status,
115-
} )
68+
if (status === HttpStatus.PAYLOAD_TOO_LARGE) {
69+
code = HttpStatus[HttpStatus.PAYLOAD_TOO_LARGE]
70+
message = `
71+
Your request entity size is too big for the server to process it:
72+
- request size: ${getObjectValue(exception, 'length')};
73+
- request limit: ${getObjectValue(exception, 'limit')}.`
74+
}
75+
// const exceptionStack : string = 'stack' in exception ? exception.stack : ''
76+
if (status >= HttpStatus.INTERNAL_SERVER_ERROR) {
77+
this.logger.error(`${status} [${request.method} ${request.url}] has thrown a critical error`)
78+
this.logger.error(`${JSON.stringify(exception)}`)
79+
} else {
80+
if (status >= HttpStatus.BAD_REQUEST) {
81+
this.logger.warn(`${status} [${request.method} ${request.url}] has thrown an HTTP client error`, exception)
82+
}
11683
}
117-
}
84+
85+
response.status(status).send({
86+
code,
87+
message,
88+
status,
89+
})
90+
}
91+
}

apps/server/src/common/libraries/domain/aggregate-logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export class AggregateLogger {
3434

3535

3636
constructor(entity: any) {
37-
this.aggregateVersion = `[V${entity.version}]`
38-
this.aggregateId = `[ID | ${entity.id}]`
37+
this.aggregateId = entity.id
38+
this.aggregateVersion = entity.version.toString()
3939
const aggregateName = entity.constructor.name.toLowerCase()
4040

4141
this.logger = new Logger(aggregateName)
Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
import {
2-
err,
3-
ok,
4-
Result,
5-
} from 'neverthrow'
1+
import {err, ok, Result} from 'neverthrow'
62

73

84

9-
export type SpecificationUnit = (...args : any[]) => Result<boolean, any>
5+
export type SpecificationUnit = (...args: any[]) => Result<boolean, any>
106

117

12-
export class BasePolicy
13-
{
14-
merge(...args : Result<boolean, any>[]) : Result<boolean, any>
15-
{
16-
for ( const result of args )
17-
{
18-
if ( result.isErr() )
19-
{
20-
return err( result.error )
21-
}
22-
}
23-
return ok( true )
8+
export class BasePolicy {
9+
merge(...args: Result<boolean, Error>[]): Result<boolean, Error> {
10+
let error: Error | undefined
11+
let result: boolean = false
12+
13+
for (const result of args) {
14+
if (result.isErr()) {
15+
error = result.error
16+
break
17+
}
18+
}
19+
20+
if (error) {
21+
return err(error)
22+
} else {
23+
return ok(true)
2424
}
25-
}
25+
}
26+
}

0 commit comments

Comments
 (0)