noot
This commit is contained in:
parent
de1379be91
commit
5b40473b5e
@ -3,6 +3,17 @@ import { c } from '#/di'
|
||||
import type { InteractionRef } from '#/discord'
|
||||
import { InteractionResponseTypes } from '@discordeno/types'
|
||||
import { Bot } from '#/discord/bot'
|
||||
import { ApplicationError } from '@temporalio/activity'
|
||||
import { logger } from '#/logger'
|
||||
|
||||
const log = logger.child({ component: 'discord-activity' })
|
||||
|
||||
// Custom error class for non-retryable Discord errors
|
||||
export class DiscordInteractionExpiredError extends ApplicationError {
|
||||
constructor(message: string) {
|
||||
super(message, { nonRetryable: true })
|
||||
}
|
||||
}
|
||||
|
||||
// from https://github.com/discordeno/discordeno/blob/21.0.0/packages/bot/src/transformers/interaction.ts#L33
|
||||
export const reply_to_interaction = async (props: {
|
||||
@ -20,6 +31,7 @@ export const reply_to_interaction = async (props: {
|
||||
data.flags = MessageFlags.Ephemeral
|
||||
}
|
||||
|
||||
try {
|
||||
switch (type) {
|
||||
case InteractionResponseTypes.UpdateMessage:
|
||||
if(ref.acknowledged) {
|
||||
@ -32,4 +44,38 @@ export const reply_to_interaction = async (props: {
|
||||
}
|
||||
return await bot.helpers.sendInteractionResponse(ref.id, ref.token, { type, data }, { withResponse: options?.withResponse })
|
||||
}
|
||||
} catch (error: any) {
|
||||
// Check if it's a Discord API error
|
||||
if (error.status === 404 || error.code === 10062) {
|
||||
// 10062 is Discord's "Unknown interaction" error code
|
||||
log.warn(
|
||||
{
|
||||
interactionId: ref.id,
|
||||
error: error.message,
|
||||
code: error.code,
|
||||
status: error.status
|
||||
},
|
||||
'Discord interaction expired (404) - not retrying'
|
||||
)
|
||||
|
||||
// Throw non-retryable error to prevent Temporal from retrying
|
||||
throw new DiscordInteractionExpiredError(
|
||||
`Discord interaction ${ref.id} has expired and cannot be responded to`
|
||||
)
|
||||
}
|
||||
|
||||
// Log other errors and re-throw them (these will be retried by Temporal)
|
||||
log.error(
|
||||
{
|
||||
interactionId: ref.id,
|
||||
error: error.message,
|
||||
stack: error.stack,
|
||||
code: error.code,
|
||||
status: error.status
|
||||
},
|
||||
'Failed to reply to Discord interaction'
|
||||
)
|
||||
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user