Skip to content

Commit

Permalink
Merge pull request #244 from EATSTEAK/feat/unclaim_error
Browse files Browse the repository at this point in the history
`CantUnclaim` 오류 추가
  • Loading branch information
Twince authored Sep 8, 2022
2 parents b5794ca + f936f7d commit 7ab98e3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
9 changes: 5 additions & 4 deletions packages/client/src/lib/api/locker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BadRequestErrorSchema,
BlockedErrorSchema,
CantClaimErrorSchema,
CantUnclaimErrorSchema,
createErrorResponse,
createSuccessResponse,
ForbiddenErrorSchema,
Expand Down Expand Up @@ -111,7 +112,7 @@ export async function apiClaimLocker(

export async function apiUnclaimLocker(): Promise<
| SuccessResponse<UnclaimLockerResponse>
| ErrorResponse<BlockedError | ForbiddenError | CantClaimError>
| ErrorResponse<BlockedError | ForbiddenError | CantUnclaimError>
> {
const response = await apiRequest<UnclaimLockerResponse>('/locker/unclaim', true, {
method: 'POST'
Expand All @@ -128,9 +129,9 @@ export async function apiUnclaimLocker(): Promise<
if (forbidden.success) {
return forbidden.data as ErrorResponse<ForbiddenError>;
}
const cantClaim = createErrorResponse(CantClaimErrorSchema).safeParse(response);
if (cantClaim.success) {
return cantClaim.data as ErrorResponse<CantClaimError>;
const cantUnclaim = createErrorResponse(CantUnclaimErrorSchema).safeParse(response);
if (cantUnclaim.success) {
return cantUnclaim.data as ErrorResponse<CantUnclaimError>;
}
const other = createErrorResponse().parse(response);
throw other.error;
Expand Down
7 changes: 7 additions & 0 deletions packages/client/src/lib/api/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/locker/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 });
}
};

Expand Down
6 changes: 6 additions & 0 deletions packages/server/src/util/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export class CantClaimError extends LockerError {
}
}

export class CantUnclaimError extends LockerError {
constructor(message?: string, additionalInfo?: Record<string, unknown>) {
super(403, 'CantUnclaim', message, additionalInfo);
}
}

export class InternalError extends LockerError {
constructor(message?: string, additionalInfo?: Record<string, unknown>) {
super(500, 'InternalError', message, additionalInfo);
Expand Down
5 changes: 5 additions & 0 deletions packages/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ type CantClaimError = LockerError & {
name: 'CantClaim';
};

type CantUnclaimError = LockerError & {
code: 403;
name: 'CantUnclaim';
};

type InternalError = LockerError & {
code: 500;
name: 'InternalError';
Expand Down

0 comments on commit 7ab98e3

Please sign in to comment.