Skip to content

Commit

Permalink
Merge pull request #82 from donghquinn/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
donghquinn authored Mar 14, 2024
2 parents 604ba85 + d89ceec commit f744435
Show file tree
Hide file tree
Showing 19 changed files with 453 additions and 645 deletions.
10 changes: 2 additions & 8 deletions src/dto/response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { AuthError } from '@errors/auth.error';
import { ClientError } from '@errors/client.error';
import { GeekError } from '@errors/geek.error';
import { HackerError } from '@errors/hacker.error';
import { MachineLearningError } from '@errors/machine.error';
import { GeekError, HackerError, MachineLearningError } from '@errors/news.error';
import { PrismaError } from '@errors/prisma.error';
import { ValidatorError } from '@errors/validator.error';

Expand Down Expand Up @@ -36,10 +33,7 @@ export class SetErrorResponse implements ResponseObject {
constructor(error: unknown) {
const errorArray = [];

if (error instanceof AuthError) {
this.resCode = '401';
errorArray.push(error.type, error.message);
} else if (error instanceof ClientError) {
if (error instanceof ClientError) {
this.resCode = '402';
errorArray.push(error.type, error.message);
} else if (error instanceof HackerError) {
Expand Down
13 changes: 0 additions & 13 deletions src/errors/auth.error.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/errors/geek.error.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/errors/hacker.error.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/errors/machine.error.ts

This file was deleted.

41 changes: 41 additions & 0 deletions src/errors/news.error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export class GeekError extends Error {
type: string;

constructor(type: string, message: string, cause?: Error) {
super(message);

this.type = type;

this.name = '[Geek Error]';

this.cause = cause;
}
}

export class HackerError extends Error {
type: string;

constructor(type: string, message: string, cause?: Error) {
super(message);

this.type = type;

this.name = '[Hacker News Error]';

this.cause = cause;
}
}

export class MachineLearningError extends Error {
type: string;

constructor(type: string, message: string, cause?: Error) {
super(message);

this.type = type;

this.name = '[Machine Learning Error]';

this.cause = cause;
}
}
4 changes: 1 addition & 3 deletions src/middlewares/header.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ export const globalMiddleware = (request: Request, res: Response, next: NextFunc
Logger.debug('Auth Key Detected');

next();
} else {
throw new HttpException('Authorize Key Not Match', HttpStatus.BAD_REQUEST);
}
} else throw new HttpException('Authorize Key Not Match', HttpStatus.BAD_REQUEST);
};
10 changes: 7 additions & 3 deletions src/providers/account-manager.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class AccountManager {
* REDIS 에 등록된 회원 정보(로그인 상태 정보) 삭제
* @param encodedEmail 암호화된 유저 이메일(REDIS 키)
*/
public async deleteItem(encodedEmail: string) {
public async deleteItem(encodedEmail: string): Promise<boolean> {
try {
const index = this.keyList.findIndex((item) => item === encodedEmail);

Expand All @@ -56,7 +56,11 @@ export class AccountManager {
await this.redis.del(encodedEmail);
await this.redis.disconnect();
ManagerLogger.info('[DELETE] Deleted User Info from Key List and Cache Data');

return true;
}

return false;
} catch (error) {
ManagerLogger.error('[DELETE] Delete User Item Error: %o', {
error,
Expand Down Expand Up @@ -134,15 +138,15 @@ export class AccountManager {
userKey: this.keyList,
});

if (key === undefined) return null;
if (key === undefined) return false;

ManagerLogger.info('[GET] Found key from keyList');

await this.redis.connect();
const gotItem = await this.redis.get(key);
await this.redis.disconnect();

if (gotItem === null) return null;
if (gotItem === null) return false;

const returnData = JSON.parse(gotItem) as ClientLoginItem;

Expand Down
Loading

0 comments on commit f744435

Please sign in to comment.