From 59533e5f0c64646f159af726122ceef0788ccf10 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 7 Apr 2025 12:38:48 +0200 Subject: [PATCH] Handle 404 for user accounts --- api/src/auth.ts | 3 ++- api/src/controllers/watchlist.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/api/src/auth.ts b/api/src/auth.ts index f8b3638b..c9d64614 100644 --- a/api/src/auth.ts +++ b/api/src/auth.ts @@ -1,6 +1,7 @@ import { TypeCompiler } from "@sinclair/typebox/compiler"; import Elysia, { t } from "elysia"; import { createRemoteJWKSet, jwtVerify } from "jose"; +import { KError } from "./models/error"; const jwtSecret = process.env.JWT_SECRET ? new TextEncoder().encode(process.env.JWT_SECRET) @@ -86,7 +87,7 @@ const User = t.Object({ }), ), }); -const UserC = TypeCompiler.Compile(User); +const UserC = TypeCompiler.Compile(t.Union([User, KError])); export async function getUserInfo( id: string, diff --git a/api/src/controllers/watchlist.ts b/api/src/controllers/watchlist.ts index 324e8a20..622f5460 100644 --- a/api/src/controllers/watchlist.ts +++ b/api/src/controllers/watchlist.ts @@ -174,6 +174,15 @@ export const watchlistH = new Elysia({ tags: ["profiles"] }) authorization: t.TemplateLiteral("Bearer ${string}"), "accept-language": AcceptLanguage({ autoFallback: true }), }), + response: { + 200: Page(Show), + 403: KError, + 404: { + ...KError, + description: "No user found with the specified id/username.", + }, + 422: KError, + }, permissions: ["users.read"], }, ),