Skip to content

Commit 5a73ecf

Browse files
committed
Fix thread creation failures showing as successfully delivered
1 parent 0394160 commit 5a73ecf

3 files changed

Lines changed: 43 additions & 23 deletions

File tree

services/backend-api/client/src/features/feed/components/UserFeedLogs/DeliveryHistory/index.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,19 +275,21 @@ export const DeliveryHistory = () => {
275275
</Td>
276276
<Td>
277277
<Skeleton isLoaded={fetchStatus === "idle"}>
278-
{item.details?.message}
279-
{item.details?.data && (
280-
<Button
281-
leftIcon={<Search2Icon />}
282-
size="xs"
283-
variant="outline"
284-
onClick={() =>
285-
setDetailsData(JSON.stringify(item.details?.data, null, 2))
286-
}
287-
>
288-
View Details
289-
</Button>
290-
)}
278+
<HStack>
279+
<span>{item.details?.message}</span>
280+
{item.details?.data && (
281+
<Button
282+
leftIcon={<Search2Icon />}
283+
size="xs"
284+
variant="outline"
285+
onClick={() =>
286+
setDetailsData(JSON.stringify(item.details?.data, null, 2))
287+
}
288+
>
289+
View Details
290+
</Button>
291+
)}
292+
</HStack>
291293
</Skeleton>
292294
</Td>
293295
</Tr>

services/user-feeds/src/delivery-record/delivery-record.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ export class DeliveryRecordService {
301301
record.error_code === ArticleDeliveryErrorCode.ThirdPartyBadRequest
302302
) {
303303
details.message = "Invalid message format";
304+
305+
try {
306+
if (record.external_detail) {
307+
details.data = JSON.parse(record.external_detail);
308+
}
309+
} catch (err) {}
304310
} else if (
305311
record.error_code === ArticleDeliveryErrorCode.ThirdPartyForbidden
306312
) {

services/user-feeds/src/delivery/mediums/discord-medium.service.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,9 @@ export class DiscordMediumService implements DeliveryMedium {
636636
body: threadBody,
637637
});
638638

639-
if (!res.success) {
639+
if (!res.success || res.status >= 300 || res.status < 200) {
640640
throw new Error(
641-
`Failed to create initial thread for webhok forum ${webhookId}: ${
641+
`Failed to create initial thread for webhook forum ${webhookId}: ${
642642
res.detail
643643
}. Body: ${JSON.stringify(res.body)}`
644644
);
@@ -759,7 +759,7 @@ export class DiscordMediumService implements DeliveryMedium {
759759
ArticleDeliveryContentType.DiscordThreadCreation
760760
);
761761

762-
if (!res.success) {
762+
if (!res.success || res.status >= 300 || res.status < 200) {
763763
return threadCreationDeliveryStates;
764764
}
765765

@@ -1115,6 +1115,12 @@ export class DiscordMediumService implements DeliveryMedium {
11151115
contentType: ArticleDeliveryContentType
11161116
): ArticleDeliveryState[] {
11171117
if (!response.success) {
1118+
throw new Error(
1119+
`Failed to create thread for medium ${details.mediumId}: ${
1120+
response.detail
1121+
}. Body: ${JSON.stringify(response.body)}`
1122+
);
1123+
} else {
11181124
if (response.status === 404) {
11191125
return [
11201126
{
@@ -1158,14 +1164,20 @@ export class DiscordMediumService implements DeliveryMedium {
11581164
article,
11591165
},
11601166
];
1161-
} else {
1162-
throw new Error(
1163-
`Failed to create thread for medium ${details.mediumId}: ${
1164-
response.detail
1165-
}. Body: ${JSON.stringify(response.body)}`
1166-
);
1167+
} else if (response.status > 300 || response.status < 200) {
1168+
return [
1169+
{
1170+
id: generateDeliveryId(),
1171+
status: ArticleDeliveryStatus.Failed,
1172+
mediumId: details.mediumId,
1173+
articleIdHash: article.flattened.idHash,
1174+
errorCode: ArticleDeliveryErrorCode.ThirdPartyBadRequest,
1175+
internalMessage: `Response: ${JSON.stringify(response.body)}`,
1176+
article,
1177+
},
1178+
];
11671179
}
1168-
} else {
1180+
11691181
return [
11701182
{
11711183
id: generateDeliveryId(),

0 commit comments

Comments
 (0)