Skip to content

Commit 46d0c35

Browse files
committed
Hoist emote set result and defer assignments
Declare a typed `result` variable outside the try block, assign it from `getOrCreateEmoteSet` inside the try, and move the `emoteSetId`/`createdNewSet` assignments to immediately after successful creation. Adds a comment explaining this ensures cleanup can use the created set info even if later operations fail.
1 parent cdbf7ed commit 46d0c35

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/pages/api/test-emote-set.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,14 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
5858
const stvResponse = await get7TVUser(twitchId)
5959
const userId = stvResponse.user.id
6060

61+
let result: { emoteSetId: string; created: boolean }
6162
try {
62-
const result = await getOrCreateEmoteSet({
63+
result = await getOrCreateEmoteSet({
6364
client,
6465
userId,
6566
twitchId,
6667
name: `TestEmoteSet${Date.now()}`.replace(/\s+/g, ''),
6768
})
68-
emoteSetId = result.emoteSetId
69-
createdNewSet = result.created
7069
} catch (error) {
7170
if (error instanceof Error && error.message.includes('permission')) {
7271
console.log('User does not have permission to use personal emote sets, skipping test')
@@ -75,6 +74,11 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
7574
throw error
7675
}
7776

77+
// Capture emoteSetId and createdNewSet immediately after successful creation
78+
// This ensures cleanup happens even if subsequent operations fail
79+
emoteSetId = result.emoteSetId
80+
createdNewSet = result.created
81+
7882
// Add emotes to the set
7983
console.log('Adding emotes to emote set...')
8084
try {

0 commit comments

Comments
 (0)