( details: ValidationDetailItem[], requestId: string, )
| 56 | } |
| 57 | |
| 58 | function buildValidationEnvelope( |
| 59 | details: ValidationDetailItem[], |
| 60 | requestId: string, |
| 61 | ): { |
| 62 | code: number; |
| 63 | msg: string; |
| 64 | data: null; |
| 65 | request_id: string; |
| 66 | details: ValidationDetailItem[]; |
| 67 | } { |
| 68 | const first = details[0]; |
| 69 | const msg = first === undefined |
| 70 | ? 'validation failed' |
| 71 | : first.path === '' |
| 72 | ? first.message |
| 73 | : `${first.path}: ${first.message}`; |
| 74 | return { |
| 75 | code: ErrorCode.VALIDATION_FAILED, |
| 76 | msg, |
| 77 | data: null, |
| 78 | request_id: requestId, |
| 79 | details, |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Build a Fastify `preHandler` that parses `req.body` against `schema`. |
no outgoing calls
no test coverage detected