Skip to content

Commit 1605a6e

Browse files
committed
refactor: add proper types and proper error handling
1 parent af28ec0 commit 1605a6e

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/servers/server.builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ export class ServerConfigBuilder {
701701
* .build();
702702
* ```
703703
*/
704-
build() {
704+
build(): Readonly<ServerConfig> {
705705
const config = deepObjMerge({}, defaultServerConfig, this.config) as ServerConfig;
706706

707707
// Common validation

src/utils/request.utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import { Request } from 'express';
2626
import { SortDirection, WithPagination } from '../types/api-response';
27+
import { BadRequestException } from './exception.utils';
2728

2829
/**
2930
* Options for parsing and validating request parameters.
@@ -96,7 +97,7 @@ export function parseNumberParam(value: string | undefined, options: ValidationO
9697
if (value === undefined) {
9798
if (required) {
9899
const error = `Required number parameter is missing`;
99-
if (throwOnError) throw new Error(error);
100+
if (throwOnError) throw new BadRequestException(error);
100101
return { isValid: false, value: null, error };
101102
}
102103

@@ -110,7 +111,7 @@ export function parseNumberParam(value: string | undefined, options: ValidationO
110111
// Parse and validate the number
111112
const num = Number(value);
112113
if (isNaN(num)) {
113-
if (throwOnError) throw new Error(errorMessage);
114+
if (throwOnError) throw new BadRequestException(errorMessage);
114115
return { isValid: false, value: null, error: errorMessage };
115116
}
116117

@@ -134,7 +135,7 @@ export function parseBooleanParam(
134135
if (value === undefined) {
135136
if (required) {
136137
const error = `Required boolean parameter is missing`;
137-
if (throwOnError) throw new Error(error);
138+
if (throwOnError) throw new BadRequestException(error);
138139
return { isValid: false, value: null, error };
139140
}
140141

@@ -155,7 +156,7 @@ export function parseBooleanParam(
155156
return { isValid: true, value: false };
156157
}
157158

158-
if (throwOnError) throw new Error(errorMessage);
159+
if (throwOnError) throw new BadRequestException(errorMessage);
159160
return { isValid: false, value: null, error: errorMessage };
160161
}
161162

0 commit comments

Comments
 (0)