Skip to content

Commit 29eb70c

Browse files
committed
Removed catch block for schema validation
1 parent 77aa5c5 commit 29eb70c

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

packages/event-handler/src/http/middleware/validation.ts

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -122,55 +122,29 @@ async function validateRequest(
122122
data: unknown,
123123
component: 'body' | 'headers' | 'path' | 'query'
124124
): Promise<unknown> {
125-
try {
126-
const result = await schema['~standard'].validate(data);
125+
const result = await schema['~standard'].validate(data);
127126

128-
if ('issues' in result) {
129-
const message = `Validation failed for request ${component}`;
130-
const error = new Error('Validation failed');
131-
throw new RequestValidationError(message, component, error);
132-
}
133-
134-
return result.value;
135-
} catch (error) {
136-
// Handle schemas that throw errors instead of returning issues
137-
if (error instanceof RequestValidationError) {
138-
throw error;
139-
}
127+
if ('issues' in result) {
140128
const message = `Validation failed for request ${component}`;
141-
throw new RequestValidationError(
142-
message,
143-
component,
144-
error instanceof Error ? error : new Error(String(error))
145-
);
129+
const error = new Error('Validation failed');
130+
throw new RequestValidationError(message, component, error);
146131
}
132+
133+
return result.value;
147134
}
148135

149136
async function validateResponse(
150137
schema: StandardSchemaV1,
151138
data: unknown,
152139
component: 'body' | 'headers'
153140
): Promise<unknown> {
154-
try {
155-
const result = await schema['~standard'].validate(data);
141+
const result = await schema['~standard'].validate(data);
156142

157-
if ('issues' in result) {
158-
const message = `Validation failed for response ${component}`;
159-
const error = new Error('Validation failed');
160-
throw new ResponseValidationError(message, component, error);
161-
}
162-
163-
return result.value;
164-
} catch (error) {
165-
// Handle schemas that throw errors instead of returning issues
166-
if (error instanceof ResponseValidationError) {
167-
throw error;
168-
}
143+
if ('issues' in result) {
169144
const message = `Validation failed for response ${component}`;
170-
throw new ResponseValidationError(
171-
message,
172-
component,
173-
error instanceof Error ? error : new Error(String(error))
174-
);
145+
const error = new Error('Validation failed');
146+
throw new ResponseValidationError(message, component, error);
175147
}
148+
149+
return result.value;
176150
}

0 commit comments

Comments
 (0)