Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
exception 추가 후 onErrorMap 을 통해 에러 맵핑
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Mar 1, 2024
1 parent 9737b34 commit fbbda61
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.daemawiki.domain.mail.repository;

import com.example.daemawiki.domain.mail.model.AuthCode;
import com.example.daemawiki.global.exception.h500.ExecuteFailedException;
import com.example.daemawiki.global.exception.h500.RedisConnectFailedException;
import com.example.daemawiki.global.type.RedisKey;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.ReactiveRedisOperations;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Mono;
Expand All @@ -22,11 +25,13 @@ public Mono<AuthCode> findByMail(String mail) {
return redisOperations.opsForValue().get(AUTHCODE + mail)
.map(value -> AuthCode.builder()
.mail(mail)
.code(value).build());
.code(value).build())
.onErrorMap(e -> e instanceof RedisConnectionFailureException ? RedisConnectFailedException.EXCEPTION : ExecuteFailedException.EXCEPTION);
}

public Mono<Void> delete(AuthCode authCode) {
return redisOperations.delete(AUTHCODE + authCode.getMail())
.onErrorMap(e -> e instanceof RedisConnectionFailureException ? RedisConnectFailedException.EXCEPTION : ExecuteFailedException.EXCEPTION)
.then();
}

Expand All @@ -35,6 +40,7 @@ public Mono<Void> save(AuthCode authCode) {
.set(AUTHCODE + authCode.getMail(),
authCode.getCode(),
Duration.ofHours(3))
.onErrorMap(e -> e instanceof RedisConnectionFailureException ? RedisConnectFailedException.EXCEPTION : ExecuteFailedException.EXCEPTION)
.then();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.daemawiki.domain.mail.repository;

import com.example.daemawiki.domain.mail.model.AuthMail;
import com.example.daemawiki.global.exception.h500.ExecuteFailedException;
import com.example.daemawiki.global.exception.h500.RedisConnectFailedException;
import com.example.daemawiki.global.type.RedisKey;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.ReactiveRedisOperations;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Mono;
Expand All @@ -24,17 +27,20 @@ public Mono<Void> save(AuthMail authMail) {
.set(AUTHMAIL + authMail.getMail(),
authMail.getMail(),
Duration.ofHours(3))
.onErrorMap(e -> e instanceof RedisConnectionFailureException ? RedisConnectFailedException.EXCEPTION : ExecuteFailedException.EXCEPTION)
.then();
}

public Mono<Boolean> findByMail(String mail) {
return redisOperations.opsForValue()
.get(AUTHMAIL + mail)
.hasElement();
.hasElement()
.onErrorMap(e -> e instanceof RedisConnectionFailureException ? RedisConnectFailedException.EXCEPTION : ExecuteFailedException.EXCEPTION);
}

public Mono<Void> delete(String mail) {
return redisOperations.delete(AUTHMAIL + mail)
.onErrorMap(e -> e instanceof RedisConnectionFailureException ? RedisConnectFailedException.EXCEPTION : ExecuteFailedException.EXCEPTION)
.then();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum ErrorCode {
TOKEN_REISSUE_FAILED(500, "토큰 재발급 실패"),
FILE_UPLOAD_FAILED(500, "파일 업로드 실패ㅋ"),
EXECUTE_FAILED(500, "서버 에러"),
REDIS_CONNECT_FAILED(500, "redis 연결 실패"),


TEST(400, "TEST");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.daemawiki.global.exception.h500;

import com.example.daemawiki.global.error.ErrorCode;
import com.example.daemawiki.global.error.exception.CustomException;

public class RedisConnectFailedException extends CustomException {
public static final CustomException EXCEPTION = new RedisConnectFailedException();

private RedisConnectFailedException() {
super(ErrorCode.REDIS_CONNECT_FAILED);
}

}

0 comments on commit fbbda61

Please sign in to comment.