Skip to content

Commit

Permalink
Reviewを反映
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriha-chan committed Feb 23, 2024
1 parent ea7e400 commit 3d3878b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export class NoteCreateService implements OnApplicationShutdown {
#shutdownController = new AbortController();

public static ContainsProhibitedWordsError = class extends Error {};
public static ContainsTooManyMentionsError = class extends Error {};

constructor(
@Inject(DI.config)
Expand Down Expand Up @@ -379,8 +380,8 @@ export class NoteCreateService implements OnApplicationShutdown {
}
}

if (mentionedUsers.length > (await this.roleService.getUserPolicies(user.id)).mentionLimit) {
throw new Error('Too many mentions');
if (mentionedUsers.length > 0 && mentionedUsers.length > (await this.roleService.getUserPolicies(user.id)).mentionLimit) {
throw new NoteCreateService.ContainsProhibitedWordsError();
}

const note = await this.insertNote(user, data, tags, emojis, mentionedUsers);
Expand Down
8 changes: 8 additions & 0 deletions packages/backend/src/server/api/endpoints/notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ export const meta = {
code: 'CONTAINS_PROHIBITED_WORDS',
id: 'aa6e01d3-a85c-669d-758a-76aab43af334',
},

containsTooManyMentions: {
message: 'Cannot post because it exceeds the allowed number of mentions.'
code: 'CONTAINS_TOO_MANY_MENTIONS',
id: '4de0363a-3046-481b-9b0f-feff3e211025',
},
},
} as const;

Expand Down Expand Up @@ -378,6 +384,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// TODO: 他のErrorもここでキャッチしてエラーメッセージを当てるようにしたい
if (e instanceof NoteCreateService.ContainsProhibitedWordsError) {
throw new ApiError(meta.errors.containsProhibitedWords);
} else if (e instanceof NoteCreateService.ContainsTooManyMentionsError) {
throw new ApiError(meta.errors.containsTooManyMentions);
}

throw e;
Expand Down

0 comments on commit 3d3878b

Please sign in to comment.