mirror of
https://github.com/open-reception/appointment-booking-software.git
synced 2026-09-22 08:54:52 +02:00
Added error constants
This commit is contained in:
@@ -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",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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", {
|
||||
|
||||
Reference in New Issue
Block a user