Skip to content

Commit 8f69d2a

Browse files
authored
fix: tests with new wrapping error from drizzle (#2141)
1 parent 40b886d commit 8f69d2a

4 files changed

Lines changed: 28 additions & 40 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"bullmq": "5.46.1",
7878
"date-fns": "4.1.0",
7979
"dotenv": "16.4.7",
80-
"drizzle-orm": "0.41.0",
80+
"drizzle-orm": "0.45.2",
8181
"extract-zip": "2.0.1",
8282
"fast-json-stringify": "6.0.1",
8383
"fastify": "5.8.5",

pnpm-lock.yaml

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/services/item/plugins/shortLink/shortlink.repository.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { and, asc, count, eq } from 'drizzle-orm';
1+
import { DrizzleQueryError, and, asc, count, eq } from 'drizzle-orm';
2+
import { DatabaseError } from 'pg';
23

34
import {
45
type ShortLink as CreateShortLink,
@@ -48,9 +49,9 @@ export class ShortLinkRepository {
4849
// can throw on alias conflict
4950
if (
5051
err !== null &&
51-
typeof err === 'object' &&
52-
'code' in err &&
53-
err.code === DUPLICATE_ERROR_CODE
52+
err instanceof DrizzleQueryError &&
53+
err.cause instanceof DatabaseError &&
54+
err.cause.code === DUPLICATE_ERROR_CODE
5455
) {
5556
throw new ShortLinkDuplication(alias);
5657
}
@@ -122,9 +123,9 @@ export class ShortLinkRepository {
122123
} catch (error: unknown) {
123124
if (
124125
error !== null &&
125-
typeof error === 'object' &&
126-
'code' in error &&
127-
error.code === DUPLICATE_ERROR_CODE
126+
error instanceof DrizzleQueryError &&
127+
error.cause instanceof DatabaseError &&
128+
error.cause.code === DUPLICATE_ERROR_CODE
128129
) {
129130
throw new ShortLinkDuplication(entity.alias);
130131
}

src/utils/errors.ts

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -436,33 +436,17 @@ export class InvalidJWTItem extends CoreError {
436436
}
437437
}
438438

439-
export class ShortLinkNotFound extends CoreError {
440-
constructor(shortLink: string) {
441-
super(
442-
{
443-
code: 'GERR1009',
444-
statusCode: StatusCodes.NOT_FOUND,
445-
message: FAILURE_MESSAGES.SHORT_LINK_NOT_FOUND,
446-
},
447-
shortLink,
448-
);
449-
this.origin = 'shortLink';
450-
}
451-
}
439+
export const ShortLinkNotFound = createError(
440+
'GERR1009',
441+
FAILURE_MESSAGES.SHORT_LINK_NOT_FOUND,
442+
StatusCodes.NOT_FOUND,
443+
);
452444

453-
export class ShortLinkDuplication extends CoreError {
454-
constructor(shortLink: string) {
455-
super(
456-
{
457-
code: 'GERR1010',
458-
statusCode: StatusCodes.CONFLICT,
459-
message: FAILURE_MESSAGES.SHORT_LINK_ALREADY_EXISTS,
460-
},
461-
shortLink,
462-
);
463-
this.origin = 'shortLink';
464-
}
465-
}
445+
export const ShortLinkDuplication = createError(
446+
'GERR1010',
447+
FAILURE_MESSAGES.SHORT_LINK_ALREADY_EXISTS,
448+
StatusCodes.CONFLICT,
449+
);
466450

467451
export class ShortLinkLimitExceed extends CoreError {
468452
constructor(itemId: string, platform: string) {

0 commit comments

Comments
 (0)