mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 22:09:16 +01:00
refactor(api): ♻️ Properly reuse error messages and schemas
This commit is contained in:
parent
7112a66e4c
commit
65e2e19ff1
84 changed files with 478 additions and 597 deletions
|
|
@ -7,7 +7,6 @@ import { Notes } from "@versia/kit/tables";
|
|||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { ApiError } from "~/classes/errors/api-error";
|
||||
import { config } from "~/config.ts";
|
||||
import { ErrorSchema } from "~/types/api";
|
||||
|
||||
const route = createRoute({
|
||||
method: "get",
|
||||
|
|
@ -32,7 +31,7 @@ const route = createRoute({
|
|||
"Entity not found, is remote, or the requester is not allowed to view it.",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: ErrorSchema,
|
||||
schema: ApiError.zodSchema,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -51,7 +50,7 @@ export default apiRoute((app) =>
|
|||
);
|
||||
|
||||
if (!(note && (await note.isViewableByUser(null))) || note.isRemote()) {
|
||||
throw new ApiError(404, "Note not found");
|
||||
throw ApiError.noteNotFound();
|
||||
}
|
||||
|
||||
// If base_url uses https and request uses http, rewrite request to use https
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import { Notes } from "@versia/kit/tables";
|
|||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { ApiError } from "~/classes/errors/api-error";
|
||||
import { config } from "~/config.ts";
|
||||
import { ErrorSchema } from "~/types/api";
|
||||
|
||||
const route = createRoute({
|
||||
method: "get",
|
||||
|
|
@ -37,7 +36,7 @@ const route = createRoute({
|
|||
"Entity not found, is remote, or the requester is not allowed to view it.",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: ErrorSchema,
|
||||
schema: ApiError.zodSchema,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -57,7 +56,7 @@ export default apiRoute((app) =>
|
|||
);
|
||||
|
||||
if (!(note && (await note.isViewableByUser(null))) || note.isRemote()) {
|
||||
throw new ApiError(404, "Note not found");
|
||||
throw ApiError.noteNotFound();
|
||||
}
|
||||
|
||||
const replies = await Note.manyFromSql(
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import { Notes } from "@versia/kit/tables";
|
|||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { ApiError } from "~/classes/errors/api-error";
|
||||
import { config } from "~/config.ts";
|
||||
import { ErrorSchema } from "~/types/api";
|
||||
|
||||
const route = createRoute({
|
||||
method: "get",
|
||||
|
|
@ -37,7 +36,7 @@ const route = createRoute({
|
|||
"Entity not found, is remote, or the requester is not allowed to view it.",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: ErrorSchema,
|
||||
schema: ApiError.zodSchema,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -57,7 +56,7 @@ export default apiRoute((app) =>
|
|||
);
|
||||
|
||||
if (!(note && (await note.isViewableByUser(null))) || note.isRemote()) {
|
||||
throw new ApiError(404, "Note not found");
|
||||
throw ApiError.noteNotFound();
|
||||
}
|
||||
|
||||
const replies = await Note.manyFromSql(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue