Skip to content

Commit

Permalink
Merge pull request #239 from sotatek-dev/feat/add-token
Browse files Browse the repository at this point in the history
refactor: error handling
  • Loading branch information
Sotatek-TanHoang authored Jan 7, 2025
2 parents f5f8245 + d48db82 commit 58f0705
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/constants/error.constant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum EError {
OTHER_SYSTEM_ERROR = 'OTHER_SYSTEM_ERROR',
FORBIDDEN_RESOURCE = 'FORBIDDEN_RESOURCE',
ACTION_CANNOT_PROCESSED = 'ACTION_CANNOT_PROCESSED',
DUPLICATED_ACTION = 'DUPLICATED_ACTION',
USER_NOT_FOUND = 'USER_NOT_FOUND',
WRONG_EMAIL_OR_PASS = 'WRONG_EMAIL_OR_PASS',
Expand Down
13 changes: 12 additions & 1 deletion src/modules/users/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class AdminService {
) {}
async createNewToken(payload: CreateTokenReqDto) {
if (await this.checkTokenExist(payload.assetAddress)) {
httpBadRequest(EError.DUPLICATED_ACTION);
return httpBadRequest(EError.DUPLICATED_ACTION);
}
const [symbol, decimals] = await Promise.all([
this.erc20ContractTemplate.getTokenSymbol(payload.assetAddress),
Expand Down Expand Up @@ -67,4 +67,15 @@ export class AdminService {
const [tokens, count] = await this.commonConfigRepo.getManyAndPagination(payload);
return toPageDto(tokens, payload, count);
}
async redeployToken(tokenPairId: number) {
const tokenInfo = await this.commonConfigRepo.findOneBy({ id: tokenPairId });
if (!tokenInfo) {
httpBadRequest(EError.RESOURCE_NOT_FOUND);
}
if (tokenInfo.status !== ETokenPairStatus.DEPLOY_FAILED) {
return httpBadRequest(EError.ACTION_CANNOT_PROCESSED);
}

await this.tokenDeployerService.deployTokenMina(tokenInfo.id);
}
}
8 changes: 4 additions & 4 deletions src/shared/exceptions/http-exeption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { EError } from '../../constants/error.constant.js';

// 400
export function httpBadRequest(errorCode: EError, metaData?: object) {
export function httpBadRequest(errorCode: EError, metaData?: object): never {
throw new BadRequestException({
statusCode: 400,
errorCode,
Expand All @@ -18,7 +18,7 @@ export function httpBadRequest(errorCode: EError, metaData?: object) {
}

// 401
export function httpUnAuthorized(errorCode?: EError, metaData?: object) {
export function httpUnAuthorized(errorCode?: EError, metaData?: object): never {
throw new UnauthorizedException({
statusCode: 401,
errorCode: errorCode || EError.UNAUTHORIZED,
Expand All @@ -27,7 +27,7 @@ export function httpUnAuthorized(errorCode?: EError, metaData?: object) {
}

// 403
export function httpForbidden(errorCode?: EError, metaData?: object) {
export function httpForbidden(errorCode?: EError, metaData?: object): never {
throw new ForbiddenException({
statusCode: 403,
errorCode: errorCode || EError.FORBIDDEN_RESOURCE,
Expand All @@ -36,7 +36,7 @@ export function httpForbidden(errorCode?: EError, metaData?: object) {
}

// 404
export function httpNotFound(errorCode: EError, metaData?: object) {
export function httpNotFound(errorCode: EError, metaData?: object): never {
throw new NotFoundException({
statusCode: 404,
errorCode,
Expand Down

0 comments on commit 58f0705

Please sign in to comment.