From 00e4141ff8b44a6740f8fe4374e6d2e90c269457 Mon Sep 17 00:00:00 2001 From: Hendrik Belitz Date: Wed, 17 Sep 2025 16:18:55 +0200 Subject: [PATCH] Added error constants --- src/lib/errors.ts | 4 ++++ src/routes/api/tenants/[id]/agents/[agentId]/+server.ts | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/errors.ts b/src/lib/errors.ts index 7728588..62a49bc 100644 --- a/src/lib/errors.ts +++ b/src/lib/errors.ts @@ -17,6 +17,7 @@ export const ERRORS = { NAME_EXISTS: "A tenant with this short name already exists", NO_TENANT_ID: "No tenant id given", NOT_FOUND: "Tenant not found", + MISSING_TENANT_OR_AGENT_ID: "Missing tenant or agent ID", }, CHANNELS: { NOT_FOUND: "Channel not found", @@ -26,4 +27,7 @@ export const ERRORS = { EMAIL_EXISTS: "E-Mail Address already exists", FAILED_TO_UPDATE: "Failed to update user data", }, + AGENTS: { + NOT_FOUND: "Agent not found", + }, }; diff --git a/src/routes/api/tenants/[id]/agents/[agentId]/+server.ts b/src/routes/api/tenants/[id]/agents/[agentId]/+server.ts index 6da181d..6a2461e 100644 --- a/src/routes/api/tenants/[id]/agents/[agentId]/+server.ts +++ b/src/routes/api/tenants/[id]/agents/[agentId]/+server.ts @@ -11,6 +11,7 @@ import type { RequestHandler } from "@sveltejs/kit"; import { registerOpenAPIRoute } from "$lib/server/openapi"; import logger from "$lib/logger"; import { checkPermission } from "$lib/server/utils/permissions"; +import { ERRORS } from "$lib/errors"; // Register OpenAPI documentation for GET registerOpenAPIRoute("/tenants/{id}/agents/{agentId}", "GET", { @@ -293,7 +294,7 @@ export const GET: RequestHandler = async ({ params, locals }) => { // Check if user is authenticated if (!tenantId || !agentId) { - throw new ValidationError("Missing tenant or agent ID"); + throw new ValidationError(ERRORS.TENANTS.MISSING_TENANT_OR_AGENT_ID); } checkPermission(locals, tenantId); @@ -340,7 +341,7 @@ export const PUT: RequestHandler = async ({ params, request, locals }) => { // Check if user is authenticated if (!tenantId || !agentId) { - throw new ValidationError("Missing tenant or agent ID"); + throw new ValidationError(ERRORS.TENANTS.MISSING_TENANT_OR_AGENT_ID); } checkPermission(locals, tenantId, true); @@ -385,7 +386,7 @@ export const DELETE: RequestHandler = async ({ params, locals }) => { const agentId = params.agentId; if (!tenantId || !agentId) { - throw new ValidationError("Missing tenant or agent ID"); + throw new ValidationError(ERRORS.TENANTS.MISSING_TENANT_OR_AGENT_ID); } checkPermission(locals, tenantId, true); @@ -400,7 +401,7 @@ export const DELETE: RequestHandler = async ({ params, locals }) => { const deleted = await agentService.deleteAgent(agentId); if (!deleted) { - throw new NotFoundError("Agent not found"); + throw new NotFoundError(ERRORS.AGENTS.NOT_FOUND); } log.debug("Agent deleted successfully", {