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 cff6c8c commit 25168f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,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 IdentifiableError('9f466dab-c856-48cd-9e65-ff90ff750580', 'Note contains too many mentions');
}

const note = await this.insertNote(user, data, tags, emojis, mentionedUsers);
Expand Down
13 changes: 11 additions & 2 deletions packages/backend/src/server/api/endpoints/notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,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,9 +384,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} catch (e) {
// TODO: 他のErrorもここでキャッチしてエラーメッセージを当てるようにしたい
if (e instanceof IdentifiableError) {
if (e.id === '689ee33f-f97c-479a-ac49-1b9f8140af99') throw new ApiError(meta.errors.containsProhibitedWords);
if (e.id === '689ee33f-f97c-479a-ac49-1b9f8140af99') {
throw new ApiError(meta.errors.containsProhibitedWords);
} else if (e.id === '9f466dab-c856-48cd-9e65-ff90ff750580') {
throw new ApiError(meta.errors.containsTooManyMentions);
}
}

throw e;
}
});
Expand Down

0 comments on commit 25168f3

Please sign in to comment.