Add proper error type & error handling

This commit is contained in:
Zoe Roux
2024-12-08 22:23:49 +01:00
parent c8c6cccf6a
commit cdceb1a734
5 changed files with 56 additions and 7 deletions
+4 -3
View File
@@ -1,15 +1,15 @@
import Elysia, { t } from "elysia";
import Elysia from "elysia";
import { Movie, SeedMovie } from "~/models/movie";
import { seedMovie, SeedMovieResponse } from "./movies";
import { Resource } from "~/models/utils";
import { comment } from "~/utils";
import { KError } from "~/models/error";
export const seed = new Elysia()
.model({
movie: Movie,
"seed-movie": SeedMovie,
"seed-movie-response": SeedMovieResponse,
error: t.String(),
})
.post(
"/movies",
@@ -25,7 +25,7 @@ export const seed = new Elysia()
description: "Existing movie edited/updated.",
},
201: { ...SeedMovieResponse, description: "Created a new movie." },
400: "error",
400: { ...KError, description: "Invalid translation name" },
409: {
...Resource,
description: comment`
@@ -33,6 +33,7 @@ export const seed = new Elysia()
Change the slug and re-run the request.
`,
},
422: { ...KError, description: "Invalid schema in body." },
},
detail: {
tags: ["movies"],
+1 -1
View File
@@ -171,7 +171,7 @@ export const seedMovie = async (
}
return {
status: ret.updated ? "Ok" : "Created",
status: ret.updated ? "OK" : "Created",
id: ret.id,
slug: ret.slug,
videos: retVideos,