From 8c588146bceb962dd153222886419f7bdcbe1a74 Mon Sep 17 00:00:00 2001 From: Andrei Jiroh Halili Date: Thu, 18 Jul 2024 16:04:36 +0800 Subject: [PATCH] docs(golinks): improve API docs for POST /api/discord-invites Expect to expand this into more soon. Signed-off-by: Andrei Jiroh Halili --- apps/golinks-v2/src/api/discord.ts | 44 ++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/apps/golinks-v2/src/api/discord.ts b/apps/golinks-v2/src/api/discord.ts index 016b805..aa81cbb 100644 --- a/apps/golinks-v2/src/api/discord.ts +++ b/apps/golinks-v2/src/api/discord.ts @@ -40,11 +40,35 @@ export class DiscordInviteLinkCreate extends OpenAPIRoute { responses: { "200": { description: "Returns Discord invite code information", - contentJson: { - schema: z.object({ - success: z.boolean().default(true), - result: DiscordInvites, - }), + content: { + "application/json": { + schema: z.object({ + success: z.boolean().default(true), + result: DiscordInvites, + }), + }, + }, + }, + "401": { + description: "Missing or invalid admin token", + content: { + "application/json": { + schema: z.object({ + success: z.boolean().default(false), + error: z.string().default("Unauthorized") + }) + } + } + }, + "409": { + description: "Returns a error when the slug is already in use.", + content: { + "application/json": { + schema: z.object({ + success: z.boolean().default(false), + error: z.string().default("The provided slug already exists."), + }), + }, }, }, }, @@ -67,6 +91,16 @@ export class DiscordInviteLinkCreate extends OpenAPIRoute { ); } catch (error) { console.error(error); + if (error.code === "P2002") { + return c.newResponse( + JSON.stringify({ + success: false, + error: "The provided slug already exists.", + }), + 409, + { "Content-Type": "application/json" }, + ); + } return c.newResponse( JSON.stringify({ success: false, -- 2.51.2