Merge branch 'fix/10332-internal-error-on-nonexisting-emoji' into 'develop'
Throw a proper ApiError with statusCode 404 when GETting a non-existing emoji. Closes #10332 See merge request firefish/firefish!10523
This commit is contained in:
commit
a2d81850e4
1 changed files with 15 additions and 1 deletions
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue