Skip to content

Commit dd6902b

Browse files
committed
refactor: response messgage and add try-catch
1 parent bee81df commit dd6902b

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/controllers/taskUpdatesHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const sendTaskUpdatesHandler = async (request: IRequest, env: env) => {
1717
const { completed, planned, blockers } = updates.content;
1818
await sendTaskUpdate(completed, planned, blockers, env);
1919
return new JSONResponse(
20-
"Task update sent on discord tracking updates channel."
20+
"Task update sent on Discord's tracking-updates channel."
2121
);
2222
} catch (error: any) {
2323
return new JSONResponse({

src/utils/sendTaskUpdates.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@ export async function sendTaskUpdate(
1212
content: formattedString,
1313
};
1414
const url = config(env).TRACKING_CHANNEL_URL;
15-
await fetch(url, {
16-
method: "POST",
17-
body: JSON.stringify(bodyObj),
18-
headers: {
19-
"Content-Type": "application/json",
20-
Authorization: `Bot ${env.DISCORD_TOKEN}`,
21-
},
22-
});
23-
return;
15+
try {
16+
const response = await fetch(url, {
17+
method: "POST",
18+
body: JSON.stringify(bodyObj),
19+
headers: {
20+
"Content-Type": "application/json",
21+
Authorization: `Bot ${env.DISCORD_TOKEN}`,
22+
},
23+
});
24+
25+
if (!response.ok) {
26+
throw new Error(
27+
`Failed to send task update: ${response.status} - ${response.statusText}`
28+
);
29+
}
30+
} catch (error) {
31+
console.error("Error occurred while sending task update:", error);
32+
throw error;
33+
}
2434
}

0 commit comments

Comments
 (0)