(fn, context = {})
| 324 | } |
| 325 | |
| 326 | export function withErrorHandling(fn, context = {}) { |
| 327 | return async (...args) => { |
| 328 | try { |
| 329 | return await fn(...args); |
| 330 | } catch (error) { |
| 331 | const interaction = args.find((arg) => |
| 332 | arg && typeof arg === 'object' && |
| 333 | (arg.isCommand || arg.isButton || arg.isModalSubmit || arg.isStringSelectMenu || arg.isChatInputCommand || arg._isPrefixCommand) |
| 334 | ); |
| 335 | |
| 336 | if (interaction) { |
| 337 | await handleInteractionError(interaction, error, context); |
| 338 | } else { |
| 339 | logger.error('Error in non-interaction context:', error); |
| 340 | } |
| 341 | |
| 342 | return null; |
| 343 | } |
| 344 | }; |
| 345 | } |
| 346 | |
| 347 | export function createError(message, type = ErrorTypes.UNKNOWN, userMessage = null, context = {}) { |
| 348 | const normalizedContext = { |
no test coverage detected