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 { 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 a new issue