11import type { JSONValue } from '@aws-lambda-powertools/commons/types' ;
2- import { isDevMode } from '@aws-lambda-powertools/commons/utils/env ' ;
2+ import type { StandardSchemaV1 } from '@standard-schema/spec ' ;
33import type { HandlerResponse , HttpStatusCode } from '../types/http.js' ;
44import { HttpStatusCodes } from './constants.js' ;
55
@@ -174,36 +174,21 @@ class ServiceUnavailableError extends HttpError {
174174 }
175175}
176176
177- class InvalidEventError extends Error {
178- constructor ( message ?: string ) {
179- super ( message ) ;
180- this . name = 'InvalidEventError' ;
181- }
182- }
183-
184- class InvalidHttpMethodError extends Error {
185- constructor ( method : string ) {
186- super ( `HTTP method ${ method } is not supported.` ) ;
187- this . name = 'InvalidEventError' ;
188- }
189- }
190-
191177class RequestValidationError extends HttpError {
192178 readonly statusCode = HttpStatusCodes . UNPROCESSABLE_ENTITY ;
193179 readonly errorType = 'RequestValidationError' ;
194180
195181 constructor (
196- message : string ,
197- public readonly component : 'body' | 'headers' | 'path' | 'query' ,
198- public readonly originalError ?: Error ,
199- details ?: Record < string , unknown >
182+ message ?: string ,
183+ issues ?: StandardSchemaV1 . FailureResult [ 'issues' ] ,
184+ options ?: ErrorOptions
200185 ) {
201- const errorDetails =
202- isDevMode ( ) && originalError
203- ? { ... details , validationError : originalError . message }
204- : details ;
205-
206- super ( message , { cause : originalError } , errorDetails ) ;
186+ super ( message , options , {
187+ issues : issues ?. map ( ( issue ) => ( {
188+ message : issue . message ,
189+ path : issue . path ,
190+ } ) ) ,
191+ } ) ;
207192 this . name = 'RequestValidationError' ;
208193 }
209194}
@@ -213,21 +198,34 @@ class ResponseValidationError extends HttpError {
213198 readonly errorType = 'ResponseValidationError' ;
214199
215200 constructor (
216- message : string ,
217- public readonly component : 'body' | 'headers' ,
218- public readonly originalError ?: Error ,
219- details ?: Record < string , unknown >
201+ message ?: string ,
202+ issues ?: StandardSchemaV1 . FailureResult [ 'issues' ] ,
203+ options ?: ErrorOptions
220204 ) {
221- const errorDetails =
222- isDevMode ( ) && originalError
223- ? { ... details , validationError : originalError . message }
224- : details ;
225-
226- super ( message , { cause : originalError } , errorDetails ) ;
205+ super ( message , options , {
206+ issues : issues ?. map ( ( issue ) => ( {
207+ message : issue . message ,
208+ path : issue . path ,
209+ } ) ) ,
210+ } ) ;
227211 this . name = 'ResponseValidationError' ;
228212 }
229213}
230214
215+ class InvalidEventError extends Error {
216+ constructor ( message ?: string ) {
217+ super ( message ) ;
218+ this . name = 'InvalidEventError' ;
219+ }
220+ }
221+
222+ class InvalidHttpMethodError extends Error {
223+ constructor ( method : string ) {
224+ super ( `HTTP method ${ method } is not supported.` ) ;
225+ this . name = 'InvalidEventError' ;
226+ }
227+ }
228+
231229export {
232230 BadRequestError ,
233231 ForbiddenError ,
0 commit comments