fix: replace Error with BadRequestError for invalid shortId format in repository and volume creation

This commit is contained in:
Jakub Trávník 2026-01-02 10:23:48 +01:00
parent 88bb174423
commit b25ed606b2
2 changed files with 5 additions and 5 deletions

View file

@ -1,6 +1,6 @@
import crypto from "node:crypto";
import { eq, or } from "drizzle-orm";
import { ConflictError, InternalServerError, NotFoundError } from "http-errors-enhanced";
import { BadRequestError, ConflictError, InternalServerError, NotFoundError } from "http-errors-enhanced";
import { db } from "../../db/db";
import { repositoriesTable } from "../../db/schema";
import { toMessage } from "../../utils/errors";
@ -74,7 +74,7 @@ const createRepository = async (
let shortId: string;
if (providedShortId) {
if (!isValidShortId(providedShortId)) {
throw new Error(`Invalid shortId format: '${providedShortId}'. Must be 8 base64url characters.`);
throw new BadRequestError(`Invalid shortId format: '${providedShortId}'. Must be 8 base64url characters.`);
}
const shortIdInUse = await db.query.repositoriesTable.findFirst({
where: eq(repositoriesTable.shortId, providedShortId),
@ -109,7 +109,7 @@ const createRepository = async (
}
if (!repoExists && config.isExistingRepository) {
throw new InternalServerError(
throw new BadRequestError(
`Cannot access existing repository. Verify the path/credentials are correct and the repository exists.`,
);
}

View file

@ -2,7 +2,7 @@ import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { and, eq, ne } from "drizzle-orm";
import { ConflictError, InternalServerError, NotFoundError } from "http-errors-enhanced";
import { BadRequestError, ConflictError, InternalServerError, NotFoundError } from "http-errors-enhanced";
import slugify from "slugify";
import { db } from "../../db/db";
import { volumesTable } from "../../db/schema";
@ -63,7 +63,7 @@ const createVolume = async (name: string, backendConfig: BackendConfig, provided
let shortId: string;
if (providedShortId) {
if (!isValidShortId(providedShortId)) {
throw new Error(`Invalid shortId format: '${providedShortId}'. Must be 8 base64url characters.`);
throw new BadRequestError(`Invalid shortId format: '${providedShortId}'. Must be 8 base64url characters.`);
}
const shortIdInUse = await db.query.volumesTable.findFirst({
where: eq(volumesTable.shortId, providedShortId),