Throw a proper ApiError with statusCode 404 when GETting a non-existing emoji.
Closes #10332
This commit is contained in:
parent
740ebcf5cc
commit
c9526b9a31
@ -1,6 +1,7 @@
|
|||||||
import { IsNull } from "typeorm";
|
import { IsNull } from "typeorm";
|
||||||
import { Emojis } from "@/models/index.js";
|
import { Emojis } from "@/models/index.js";
|
||||||
import define from "../define.js";
|
import define from "../define.js";
|
||||||
|
import { ApiError } from "../error.js";
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ["meta"],
|
tags: ["meta"],
|
||||||
@ -9,6 +10,15 @@ export const meta = {
|
|||||||
allowGet: true,
|
allowGet: true,
|
||||||
cacheSec: 3600,
|
cacheSec: 3600,
|
||||||
|
|
||||||
|
errors: {
|
||||||
|
noSuchEmoji: {
|
||||||
|
message: "No such emoji.",
|
||||||
|
code: "NO_SUCH_EMOJI",
|
||||||
|
id: "6a5e3be7-5ac3-44a6-a425-9937cd66f8e1",
|
||||||
|
httpStatusCode: 404,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
res: {
|
res: {
|
||||||
type: "object",
|
type: "object",
|
||||||
optional: false,
|
optional: false,
|
||||||
@ -28,12 +38,16 @@ export const paramDef = {
|
|||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default define(meta, paramDef, async (ps, me) => {
|
export default define(meta, paramDef, async (ps, me) => {
|
||||||
const emoji = await Emojis.findOneOrFail({
|
const emoji = await Emojis.findOne({
|
||||||
where: {
|
where: {
|
||||||
name: ps.name,
|
name: ps.name,
|
||||||
host: IsNull(),
|
host: IsNull(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!emoji) {
|
||||||
|
throw new ApiError(meta.errors.noSuchEmoji);
|
||||||
|
}
|
||||||
|
|
||||||
return Emojis.pack(emoji);
|
return Emojis.pack(emoji);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user