2424
2525import { Request } from 'express' ;
2626import { 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