diff --git a/packages/client/src/lib/api/locker.ts b/packages/client/src/lib/api/locker.ts index abb9398d..b25f1e72 100644 --- a/packages/client/src/lib/api/locker.ts +++ b/packages/client/src/lib/api/locker.ts @@ -6,6 +6,7 @@ import { BadRequestErrorSchema, BlockedErrorSchema, CantClaimErrorSchema, + CantUnclaimErrorSchema, createErrorResponse, createSuccessResponse, ForbiddenErrorSchema, @@ -111,7 +112,7 @@ export async function apiClaimLocker( export async function apiUnclaimLocker(): Promise< | SuccessResponse - | ErrorResponse + | ErrorResponse > { const response = await apiRequest('/locker/unclaim', true, { method: 'POST' @@ -128,9 +129,9 @@ export async function apiUnclaimLocker(): Promise< if (forbidden.success) { return forbidden.data as ErrorResponse; } - const cantClaim = createErrorResponse(CantClaimErrorSchema).safeParse(response); - if (cantClaim.success) { - return cantClaim.data as ErrorResponse; + const cantUnclaim = createErrorResponse(CantUnclaimErrorSchema).safeParse(response); + if (cantUnclaim.success) { + return cantUnclaim.data as ErrorResponse; } const other = createErrorResponse().parse(response); throw other.error; diff --git a/packages/client/src/lib/api/schema.ts b/packages/client/src/lib/api/schema.ts index 1e0cdc85..bc3b4ce6 100644 --- a/packages/client/src/lib/api/schema.ts +++ b/packages/client/src/lib/api/schema.ts @@ -65,6 +65,13 @@ export const CantClaimErrorSchema = z }) .passthrough(); +export const CantUnclaimErrorSchema = z + .object({ + code: z.literal(403), + name: z.literal('CantUnclaim') + }) + .passthrough(); + export const InternalErrorSchema = z.object({ code: z.literal(500), name: z.literal('InternalError') diff --git a/packages/server/src/locker/data.ts b/packages/server/src/locker/data.ts index 9e32740d..869320ea 100644 --- a/packages/server/src/locker/data.ts +++ b/packages/server/src/locker/data.ts @@ -6,7 +6,7 @@ import type { UpdateItemOutput } from 'aws-sdk/clients/dynamodb'; import { adminId, dynamoDB, TableName } from '../util/database'; -import { CantClaimError, ForbiddenError, NotFoundError } from '../util/error'; +import { CantClaimError, CantUnclaimError, ForbiddenError, NotFoundError } from '../util/error'; import type { AWSError } from 'aws-sdk'; export const claimLocker = async function ( @@ -119,7 +119,7 @@ export const unclaimLocker = async function ( lockerId: res.Attributes.lockerId.S }; } else { - throw new CantClaimError('This user is not claimed an locker yet', { id }); + throw new CantUnclaimError('This user is not claimed an locker yet', { id }); } }; diff --git a/packages/server/src/util/error.ts b/packages/server/src/util/error.ts index a5cd5962..fe418bff 100644 --- a/packages/server/src/util/error.ts +++ b/packages/server/src/util/error.ts @@ -63,6 +63,12 @@ export class CantClaimError extends LockerError { } } +export class CantUnclaimError extends LockerError { + constructor(message?: string, additionalInfo?: Record) { + super(403, 'CantUnclaim', message, additionalInfo); + } +} + export class InternalError extends LockerError { constructor(message?: string, additionalInfo?: Record) { super(500, 'InternalError', message, additionalInfo); diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index 0e941237..e9a851e9 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -249,6 +249,11 @@ type CantClaimError = LockerError & { name: 'CantClaim'; }; +type CantUnclaimError = LockerError & { + code: 403; + name: 'CantUnclaim'; +}; + type InternalError = LockerError & { code: 500; name: 'InternalError';