File tree Expand file tree Collapse file tree
routes/subscriptions/discord Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { ErrorCode } from "@/schema/errors/ErrorCode"
99import { zInsufficientPermissionsError } from "@/schema/errors/InsufficientPermissionsError"
1010import { zInvalidDiscordAuthError } from "@/schema/errors/InvalidDiscordAuthError"
1111import {
12+ DiscordWebhookMissingPermissionsError ,
1213 deleteDiscordWebhook ,
1314 getDiscordWebhookStatus ,
1415 upsertDiscordWebhook
@@ -47,13 +48,22 @@ export const putDiscordWebhookRoute = new RaidHubRoute({
4748 message : "Forbidden" as const
4849 } )
4950 }
50- return RaidHubRoute . ok (
51- await upsertDiscordWebhook ( {
52- ...req . body ,
53- guildId,
54- channelId
55- } )
56- )
51+ try {
52+ return RaidHubRoute . ok (
53+ await upsertDiscordWebhook ( {
54+ ...req . body ,
55+ guildId,
56+ channelId
57+ } )
58+ )
59+ } catch ( err ) {
60+ if ( err instanceof DiscordWebhookMissingPermissionsError ) {
61+ return RaidHubRoute . fail ( ErrorCode . InsufficientPermissionsError , {
62+ message : "Forbidden" as const
63+ } )
64+ }
65+ throw err
66+ }
5767 }
5868} )
5969
Original file line number Diff line number Diff line change @@ -3,6 +3,13 @@ import { Logger } from "@/lib/utils/logging"
33
44const logger = new Logger ( "DISCORD_SUBSCRIPTIONS_SERVICE" )
55
6+ export class DiscordWebhookMissingPermissionsError extends Error {
7+ constructor ( channelId : string ) {
8+ super ( `Discord bot is missing permissions to create a webhook in channel ${ channelId } ` )
9+ this . name = "DiscordWebhookMissingPermissionsError"
10+ }
11+ }
12+
613export type DiscordWebhookPlayerTargetInput = {
714 membershipId : string
815 requireFresh ?: boolean
@@ -113,6 +120,9 @@ const createDiscordWebhook = async (
113120
114121 if ( ! response . ok ) {
115122 const detail = await response . text ( )
123+ if ( response . status === 403 ) {
124+ throw new DiscordWebhookMissingPermissionsError ( body . channelId )
125+ }
116126 throw new Error ( `Discord webhook create failed with status ${ response . status } : ${ detail } ` )
117127 }
118128
You can’t perform that action at this time.
0 commit comments