diff --git a/packages/backend/src/server/api/endpoints/emoji.ts b/packages/backend/src/server/api/endpoints/emoji.ts index ddfad77374..f5a5be4ec5 100644 --- a/packages/backend/src/server/api/endpoints/emoji.ts +++ b/packages/backend/src/server/api/endpoints/emoji.ts @@ -1,6 +1,7 @@ import { IsNull } from "typeorm"; import { Emojis } from "@/models/index.js"; import define from "../define.js"; +import { ApiError } from "../error.js"; export const meta = { tags: ["meta"], @@ -9,6 +10,15 @@ export const meta = { allowGet: true, cacheSec: 3600, + errors: { + noSuchEmoji: { + message: "No such emoji.", + code: "NO_SUCH_EMOJI", + id: "6a5e3be7-5ac3-44a6-a425-9937cd66f8e1", + httpStatusCode: 404, + }, + }, + res: { type: "object", optional: false, @@ -28,12 +38,16 @@ export const paramDef = { } as const; export default define(meta, paramDef, async (ps, me) => { - const emoji = await Emojis.findOneOrFail({ + const emoji = await Emojis.findOne({ where: { name: ps.name, host: IsNull(), }, }); + if (!emoji) { + throw new ApiError(meta.errors.noSuchEmoji); + } + return Emojis.pack(emoji); });