(interaction, {
type = ErrorTypes.UNKNOWN,
message,
subtype = null,
ephemeral = true,
context = {}
} = {})
| 288 | * Reply with a typed user-facing error (early-return validation, permission checks, etc.). |
| 289 | */ |
| 290 | export async function replyUserError(interaction, { |
| 291 | type = ErrorTypes.UNKNOWN, |
| 292 | message, |
| 293 | subtype = null, |
| 294 | ephemeral = true, |
| 295 | context = {} |
| 296 | } = {}) { |
| 297 | const errorType = type || ErrorTypes.UNKNOWN; |
| 298 | const syntheticError = message |
| 299 | ? createError('User error', errorType, message, { expected: true, ...context }) |
| 300 | : createError('User error', errorType, null, { expected: true, ...context }); |
| 301 | |
| 302 | const userMessage = getUserMessage(syntheticError, { subtype, ...context }); |
| 303 | const { logData, traceId } = buildErrorLogData(interaction, syntheticError, errorType, { |
| 304 | ...context, |
| 305 | subtype, |
| 306 | source: context.source || 'replyUserError' |
| 307 | }); |
| 308 | |
| 309 | logInteractionError(syntheticError, errorType, logData); |
| 310 | |
| 311 | const embed = buildUserErrorEmbed(errorType, userMessage); |
| 312 | return sendErrorResponse(interaction, embed, { ...context, traceId, ephemeral, subtype }); |
| 313 | } |
| 314 | |
| 315 | export async function handleInteractionError(interaction, error, context = {}) { |
| 316 | const errorType = categorizeError(error); |
no test coverage detected