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

Commit cce4e6d

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

File tree

28 files changed

+752
-723
lines changed

28 files changed

+752
-723
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": "Eldred.Thiel@gmail.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": "Eldred.Thiel@gmail.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": "Estevan.Collins16",
659659
"examples": [
660-
"Herman.Bauch21",
661-
"Adolf_Schiller",
662-
"Lane.Braun-Raynor73"
660+
"Fannie_Oberbrunner47",
661+
"Sasha.Harris1",
662+
"Rogelio0"
663663
]
664664
}
665665
},
@@ -727,11 +727,11 @@
727727
"username": {
728728
"type": "string",
729729
"description": "The account's username",
730-
"example": "Ronaldo.Ledner96",
730+
"example": "Estevan.Collins16",
731731
"examples": [
732-
"Herman.Bauch21",
733-
"Adolf_Schiller",
734-
"Lane.Braun-Raynor73"
732+
"Fannie_Oberbrunner47",
733+
"Sasha.Harris1",
734+
"Rogelio0"
735735
]
736736
},
737737
"method": {
@@ -762,11 +762,11 @@
762762
"refreshToken": {
763763
"type": "string",
764764
"description": "...",
765-
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
765+
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDgwMDUxfQ.XakNhfyHE6GlPyC93NUYZb03oFPFSR5IcZma53U2kDc",
766766
"examples": [
767-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
768-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
769-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98"
767+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDgwMDUxfQ.XakNhfyHE6GlPyC93NUYZb03oFPFSR5IcZma53U2kDc",
768+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDgwMDUxfQ.XakNhfyHE6GlPyC93NUYZb03oFPFSR5IcZma53U2kDc",
769+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDgwMDUxfQ.XakNhfyHE6GlPyC93NUYZb03oFPFSR5IcZma53U2kDc"
770770
]
771771
}
772772
},
@@ -783,11 +783,11 @@
783783
"refreshToken": {
784784
"type": "string",
785785
"description": "...",
786-
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
786+
"example": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDgwMDUxfQ.XakNhfyHE6GlPyC93NUYZb03oFPFSR5IcZma53U2kDc",
787787
"examples": [
788-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
789-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98",
790-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDY2ODgxfQ.3VmfJ9Iwb9pycFuVWPdda53Ck6SV82BcUg3quDE9e98"
788+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDgwMDUxfQ.XakNhfyHE6GlPyC93NUYZb03oFPFSR5IcZma53U2kDc",
789+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDgwMDUxfQ.XakNhfyHE6GlPyC93NUYZb03oFPFSR5IcZma53U2kDc",
790+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjp7fSwiaWF0IjoxNzA3NDgwMDUxfQ.XakNhfyHE6GlPyC93NUYZb03oFPFSR5IcZma53U2kDc"
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": "Eldred.Thiel@gmail.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": "Estevan.Collins16",
825825
"examples": [
826-
"Herman.Bauch21",
827-
"Adolf_Schiller",
828-
"Lane.Braun-Raynor73"
826+
"Fannie_Oberbrunner47",
827+
"Sasha.Harris1",
828+
"Rogelio0"
829829
]
830830
}
831831
},
@@ -843,11 +843,11 @@
843843
"username": {
844844
"type": "string",
845845
"description": "The account's username",
846-
"example": "Ronaldo.Ledner96",
846+
"example": "Estevan.Collins16",
847847
"examples": [
848-
"Herman.Bauch21",
849-
"Adolf_Schiller",
850-
"Lane.Braun-Raynor73"
848+
"Fannie_Oberbrunner47",
849+
"Sasha.Harris1",
850+
"Rogelio0"
851851
]
852852
},
853853
"password": {

apps/server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@
155155
"tslib": "^2.6.2",
156156
"type-fest": "^4.9.0",
157157
"typia": "^5.3.10",
158-
"untildify": "^5.0.0"
158+
"untildify": "^5.0.0",
159+
"untun": "^0.1.3"
159160
},
160161
"devDependencies": {
161162
"@automapper/types": "^6.3.1",

apps/server/src/bootstrap.ts

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
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'
12-
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'
17-
import type {ExpressRequest, ExpressResponse} from './types/express-response.js'
18-
import {portAllocator} from './utilities/network-utils/port-allocator.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 ms from 'ms'
6+
import process from 'node:process'
7+
import {LoggerNestjsProxy} from "./common/logger/nestjs-logger-proxy.js"
8+
import {buildCompodocDocumentation} from './common/modules/documentation/compodoc/compodoc.js'
9+
import {buildSwaggerDocumentation} from './common/modules/documentation/swagger/swagger.js'
10+
import {executePrismaRelatedProcesses} from './common/modules/resources/prisma/utils/execute-prisma-related-processes.js'
11+
import {__appConfig, __config} from './configs/global/__config.js'
12+
import {isDevelopment} from './configs/helper/is-development.js'
13+
import {StaticFeatureFlags} from './configs/static-feature-flags.js'
14+
import {Container} from './container.js'
15+
import {migrateDatabase} from './hooks/post-start/migrate-database.js'
16+
import {portAllocator} from './utilities/network-utils/port-allocator.js'
1917

2018

2119

@@ -24,9 +22,13 @@ export async function bootstrap() {
2422
const app = await NestFactory.create(Container, {
2523
abortOnError: false,
2624
autoFlushLogs: true,
25+
cors: true,
26+
bodyParser: true,
27+
rawBody: true,
28+
preview: false,
2729
bufferLogs: true,
2830
snapshot: isDevelopment(),
29-
logger: new NestjsLogger(),
31+
logger: new LoggerNestjsProxy(),
3032
})
3133

3234
// Implement logger used for bootstrapping and notifying about application state
@@ -51,16 +53,16 @@ export async function bootstrap() {
5153
buildCompodocDocumentation()
5254

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

5759
// Optional fallthrough error handler
58-
app.use(function onError(_err: Error, _req: ExpressRequest, res: ExpressResponse, _next: NextFunction) {
59-
res.statusCode = 500
60-
res.end((
61-
res as any
62-
).sentry + '\n')
63-
})
60+
//app.use(function onError(_err: Error, _req: ExpressRequest, res: ExpressResponse, _next: NextFunction) {
61+
// res.statusCode = 500
62+
// res.end((
63+
// res as any
64+
// ).sentry + '\n')
65+
//})
6466

6567
const PORT = __config.get('PORT')
6668

@@ -85,7 +87,7 @@ export async function bootstrap() {
8587

8688
while (!isApplicationListening) {
8789
try {
88-
await app.listen(openPort.port, () => {
90+
await app.listen(openPort.port, async () => {
8991
logger.verbose(`${'-'.repeat(54)}`)
9092
logger.log(`🚀 Application started on ${applicationUrl} in ${NODE_ENV} mode`)
9193

@@ -102,6 +104,18 @@ export async function bootstrap() {
102104
}
103105

104106
logger.verbose(`${'-'.repeat(54)}`)
107+
108+
//if (__config.get("FEATURE").ENABLE_TUNNEL) {
109+
// const tunnel = await startTunnel({
110+
// port: openPort.port,
111+
// acceptCloudflareNotice: true,
112+
// })
113+
//
114+
// if (tunnel) {
115+
// logger.verbose(`🚇 Tunnel is enabled, you can access your application via public URL: ${await tunnel.getURL()}`)
116+
// }
117+
//}
118+
105119
})
106120
isApplicationListening = true
107121
} catch (e) {

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+
}

0 commit comments

Comments
 (0)