Function: validateServicePayload()
validateServicePayload<
T>(validator:Validator<T>,value:unknown,context:ValidationContext):T
Defined in: src/services/utils/validation.ts:92
Validates a payload using a shared Zod schema and unwraps the typed result.
Type Parametersโ
Tโ
T
Parametersโ
validatorโ
Validator<T>
Function returning a safeParse-style result.
valueโ
unknown
Raw value to validate.
contextโ
Service/operation context used to format errors.
Returnsโ
T
Parsed data when validation succeeds.
Remarksโ
This helper is intentionally opinionated about the resulting error messages, following the pattern used by data-oriented services:
- When the validator throws, the error message uses the form
"[ServiceName] <operation> threw during validation". - When validation fails, the message uses the form
"[ServiceName] <operation> returned invalid payload: <issues>".
In both cases, the original error (validator exception or Zod error) is
attached via ://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error.cause. Callers are expected to allow these errors
to propagate into the existing error-handling helpers such as
withUtilityErrorHandling.
Throwsโ
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Error when validation fails or the validator itself throws.