Skip to content

Commit

Permalink
refactor: use IdentifiableError instead of NoteCreateService.Contains…
Browse files Browse the repository at this point in the history
…ProhibitedWordsError
  • Loading branch information
anatawa12 committed Feb 21, 2024
1 parent f209b24 commit 7945708
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 1 addition & 3 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ export class NoteCreateService implements OnApplicationShutdown {
private logger: Logger;
#shutdownController = new AbortController();

public static ContainsProhibitedWordsError = class extends Error {};

constructor(
@Inject(DI.config)
private config: Config,
Expand Down Expand Up @@ -271,7 +269,7 @@ export class NoteCreateService implements OnApplicationShutdown {
}

if (this.utilityService.isKeyWordIncluded(data.cw ?? data.text ?? '', meta.prohibitedWords)) {
throw new NoteCreateService.ContainsProhibitedWordsError();
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', 'Note contains prohibited words');
}

const inSilencedInstance = this.utilityService.isSilencedHost(meta.silencedHosts, user.host);
Expand Down
5 changes: 3 additions & 2 deletions packages/backend/src/server/api/endpoints/notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { isPureRenote } from '@/misc/is-pure-renote.js';
import { MetaService } from '@/core/MetaService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { ApiError } from '../../error.js';
import {IdentifiableError} from "@/misc/identifiable-error.js";

export const meta = {
tags: ['notes'],
Expand Down Expand Up @@ -376,8 +377,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
};
} catch (e) {
// TODO: 他のErrorもここでキャッチしてエラーメッセージを当てるようにしたい
if (e instanceof NoteCreateService.ContainsProhibitedWordsError) {
throw new ApiError(meta.errors.containsProhibitedWords);
if (e instanceof IdentifiableError) {
if (e.id === '689ee33f-f97c-479a-ac49-1b9f8140af99') throw new ApiError(meta.errors.containsProhibitedWords);
}

throw e;
Expand Down

0 comments on commit 7945708

Please sign in to comment.