Skip to content

Commit 4b9cf74

Browse files
committed
Fix non-descript errors when sending template previews
1 parent 73675b0 commit 4b9cf74

File tree

8 files changed

+80
-37
lines changed

8 files changed

+80
-37
lines changed

services/backend-api/client/src/features/feedConnections/hooks/useTestSendFlow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ export const useTestSendFlow = ({
137137
});
138138
}
139139
} catch (err) {
140+
const errorMessage =
141+
(err as Error).message || "Failed to send test article. Please try again.";
140142
setTestSendFeedback({
141143
status: "error",
142-
message: "Failed to send test article. Please try again.",
144+
message: errorMessage,
143145
});
144146
} finally {
145147
setIsTestSending(false);

services/backend-api/client/src/features/templates/components/TemplateGalleryModal/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,7 @@ const TemplateGalleryModalComponent = (props: TemplateGalleryModalProps) => {
690690
{testSendFeedback.status === "error" && (
691691
<Alert status="error" borderRadius="md" size="sm">
692692
<AlertIcon />
693-
<HStack justifyContent="space-between" flex={1}>
694-
<AlertDescription>{testSendFeedback.message}</AlertDescription>
695-
<Button size="sm" variant="outline" onClick={onTestSend}>
696-
Retry
697-
</Button>
698-
</HStack>
693+
<AlertDescription>{testSendFeedback.message}</AlertDescription>
699694
</Alert>
700695
)}
701696
</Box>

services/backend-api/src/features/feed-connections/filters/add-discord-channel-connection.filter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { StandardException } from "../../../common/exceptions/standard-exception
55
import { StandardBaseExceptionFilter } from "../../../common/filters/standard-exception-filter";
66
import { WebhookMissingPermissionsException } from "../../discord-webhooks/exceptions";
77
import {
8+
MissingChannelException,
89
MissingChannelPermissionsException,
910
UserMissingManageGuildException,
1011
} from "../../feeds/exceptions";
@@ -23,6 +24,10 @@ export const ADD_DISCORD_CHANNEL_CONNECTION_ERROR_CODES: Record<
2324
status: HttpStatus.BAD_REQUEST,
2425
code: ApiErrorCode.FEED_MISSING_CHANNEL,
2526
},
27+
[MissingChannelException.name]: {
28+
status: HttpStatus.BAD_REQUEST,
29+
code: ApiErrorCode.FEED_MISSING_CHANNEL,
30+
},
2631
[DiscordChannelPermissionsException.name]: {
2732
status: HttpStatus.BAD_REQUEST,
2833
code: ApiErrorCode.FEED_MISSING_CHANNEL_PERMISSION,

services/backend-api/src/features/feed-connections/filters/create-discord-channel-test-article.filter.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,40 @@ import {
88
InvalidFiltersRegexException,
99
InvalidPreviewCustomPlaceholdersRegexException,
1010
} from "../../../services/feed-fetcher/exceptions";
11+
import { MissingChannelException } from "../../feeds/exceptions";
1112
import { FeedConnectionNotFoundException } from "../exceptions";
1213

13-
const ERROR_CODES: Record<string, { status: HttpStatus; code: ApiErrorCode }> =
14-
{
15-
[FeedConnectionNotFoundException.name]: {
16-
status: HttpStatus.NOT_FOUND,
17-
code: ApiErrorCode.FEED_CONNECTION_NOT_FOUND,
18-
},
19-
[FeedArticleNotFoundException.name]: {
20-
status: HttpStatus.NOT_FOUND,
21-
code: ApiErrorCode.FEED_ARTICLE_NOT_FOUND,
22-
},
23-
[InvalidPreviewCustomPlaceholdersRegexException.name]: {
24-
status: HttpStatus.UNPROCESSABLE_ENTITY,
25-
code: ApiErrorCode.INVALID_CUSTOM_PLACEHOLDERS_REGEX_PREVIEW_INPUT,
26-
},
27-
[InvalidFiltersRegexException.name]: {
28-
status: HttpStatus.UNPROCESSABLE_ENTITY,
29-
code: ApiErrorCode.INVALID_FILTERS_REGEX,
30-
},
31-
[InvalidComponentsV2Exception.name]: {
32-
status: HttpStatus.BAD_REQUEST,
33-
code: ApiErrorCode.FEED_INVALID_COMPONENTS_V2,
34-
},
35-
};
14+
export const CREATE_DISCORD_CHANNEL_TEST_ARTICLE_ERROR_CODES: Record<
15+
string,
16+
{ status: HttpStatus; code: ApiErrorCode }
17+
> = {
18+
[FeedConnectionNotFoundException.name]: {
19+
status: HttpStatus.NOT_FOUND,
20+
code: ApiErrorCode.FEED_CONNECTION_NOT_FOUND,
21+
},
22+
[FeedArticleNotFoundException.name]: {
23+
status: HttpStatus.NOT_FOUND,
24+
code: ApiErrorCode.FEED_ARTICLE_NOT_FOUND,
25+
},
26+
[InvalidPreviewCustomPlaceholdersRegexException.name]: {
27+
status: HttpStatus.UNPROCESSABLE_ENTITY,
28+
code: ApiErrorCode.INVALID_CUSTOM_PLACEHOLDERS_REGEX_PREVIEW_INPUT,
29+
},
30+
[InvalidFiltersRegexException.name]: {
31+
status: HttpStatus.UNPROCESSABLE_ENTITY,
32+
code: ApiErrorCode.INVALID_FILTERS_REGEX,
33+
},
34+
[InvalidComponentsV2Exception.name]: {
35+
status: HttpStatus.BAD_REQUEST,
36+
code: ApiErrorCode.FEED_INVALID_COMPONENTS_V2,
37+
},
38+
[MissingChannelException.name]: {
39+
status: HttpStatus.BAD_REQUEST,
40+
code: ApiErrorCode.FEED_MISSING_CHANNEL,
41+
},
42+
};
3643

3744
@Catch(StandardException)
3845
export class CreateDiscordChannelTestArticleFilter extends StandardBaseExceptionFilter {
39-
exceptions = ERROR_CODES;
46+
exceptions = CREATE_DISCORD_CHANNEL_TEST_ARTICLE_ERROR_CODES;
4047
}

services/backend-api/src/features/feeds/feeds.service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,23 @@ export class FeedsService {
182182
userAccessToken: string;
183183
skipBotPermissionAssertions?: boolean;
184184
}) {
185-
const channel = await this.discordApiService.getChannel(channelId);
185+
let channel;
186+
187+
try {
188+
channel = await this.discordApiService.getChannel(channelId);
189+
} catch (err) {
190+
if (err instanceof DiscordAPIError) {
191+
if (err.statusCode === HttpStatus.NOT_FOUND) {
192+
throw new MissingChannelException();
193+
}
194+
195+
if (err.statusCode === HttpStatus.FORBIDDEN) {
196+
throw new MissingChannelPermissionsException();
197+
}
198+
}
199+
200+
throw err;
201+
}
186202

187203
const { isManager } = await this.discordAuthService.userManagesGuild(
188204
userAccessToken,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./retry-user-feed-exception.filter";
22
export * from "./create-user-feed-management-invite-exception.filter";
33
export * from "./get-user-feed-articles.exception.filter";
4+
export * from "./send-test-article-exception.filter";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Catch, HttpStatus } from "@nestjs/common";
2+
import { ApiErrorCode } from "../../../common/constants/api-errors";
3+
import { StandardException } from "../../../common/exceptions/standard-exception.exception";
4+
import { StandardBaseExceptionFilter } from "../../../common/filters/standard-exception-filter";
5+
import { ADD_DISCORD_CHANNEL_CONNECTION_ERROR_CODES } from "../../feed-connections/filters/add-discord-channel-connection.filter";
6+
import { CREATE_DISCORD_CHANNEL_TEST_ARTICLE_ERROR_CODES } from "../../feed-connections/filters/create-discord-channel-test-article.filter";
7+
8+
export const SEND_TEST_ARTICLE_ERROR_CODES: Record<
9+
string,
10+
{ status: HttpStatus; code: ApiErrorCode }
11+
> = {
12+
...CREATE_DISCORD_CHANNEL_TEST_ARTICLE_ERROR_CODES,
13+
...ADD_DISCORD_CHANNEL_CONNECTION_ERROR_CODES,
14+
};
15+
16+
@Catch(StandardException)
17+
export class SendTestArticleFilter extends StandardBaseExceptionFilter {
18+
exceptions = SEND_TEST_ARTICLE_ERROR_CODES;
19+
}

services/backend-api/src/features/user-feeds/user-feeds.controller.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import { DiscordOAuth2Guard } from "../discord-auth/guards/DiscordOAuth2.guard";
2323
import { FastifyReply, FastifyRequest } from "fastify";
2424
import { SessionAccessToken } from "../discord-auth/types/SessionAccessToken.type";
2525

26-
import {
27-
ADD_DISCORD_CHANNEL_CONNECTION_ERROR_CODES,
28-
CreateDiscordChannelTestArticleFilter,
29-
} from "../feed-connections/filters";
26+
import { ADD_DISCORD_CHANNEL_CONNECTION_ERROR_CODES } from "../feed-connections/filters";
3027
import { FeedConnectionsDiscordChannelsService } from "../feed-connections/feed-connections-discord-channels.service";
3128
import { FeedsService } from "../feeds/feeds.service";
3229
import {
@@ -62,6 +59,7 @@ import {
6259
import {
6360
GetUserFeedArticlesExceptionFilter,
6461
RETRY_USER_FEED_ERROR_CODES,
62+
SendTestArticleFilter,
6563
} from "./filters";
6664
import { RestoreLegacyUserFeedExceptionFilter } from "./filters/restore-legacy-user-feed-exception.filter";
6765
import { GetUserFeedsPipe, GetUserFeedsPipeOutput } from "./pipes";
@@ -241,7 +239,7 @@ export class UserFeedsController {
241239
}
242240

243241
@Post("/:feedId/test-send")
244-
@UseFilters(CreateDiscordChannelTestArticleFilter)
242+
@UseFilters(SendTestArticleFilter)
245243
async sendTestArticle(
246244
@Param(
247245
"feedId",

0 commit comments

Comments
 (0)