(interaction, context = {})
| 25 | }); |
| 26 | |
| 27 | export function validateChatInputPayloadOrThrow(interaction, context = {}) { |
| 28 | const payload = { |
| 29 | commandName: interaction?.commandName, |
| 30 | options: Array.isArray(interaction?.options?.data) ? interaction.options.data : [] |
| 31 | }; |
| 32 | |
| 33 | const parsed = CommandInputSchema.safeParse(payload); |
| 34 | if (parsed.success) { |
| 35 | return parsed.data; |
| 36 | } |
| 37 | |
| 38 | throw createError( |
| 39 | 'Invalid command input payload', |
| 40 | ErrorTypes.VALIDATION, |
| 41 | 'One or more command inputs are invalid. Please review your options and try again.', |
| 42 | { |
| 43 | ...context, |
| 44 | errorCode: 'VALIDATION_FAILED', |
| 45 | issues: parsed.error.issues.map((issue) => ({ |
| 46 | path: issue.path.join('.'), |
| 47 | message: issue.message, |
| 48 | code: issue.code |
| 49 | })) |
| 50 | } |
| 51 | ); |
| 52 | } |
no test coverage detected