Skip to content

Commit

Permalink
feat: add Exception and ExceptionHandler [#322]
Browse files Browse the repository at this point in the history
  • Loading branch information
kho903 committed Feb 13, 2022
1 parent 250b8bc commit 14cd5f2
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 9 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ public enum ErrorCode {

// NEWS
NOT_FOUND_NEWS("N001", "Not Found News"),

// TOKEN
NOT_FOUND_TOKEN("TK001", "Not Found Token"),
NOT_AUTHORITY("TK002", "Not Authority Token"),
NOT_AUTHORITY_SUPER("TK003", "Not Super Token"),

// MANGER
NOT_FOUND_MANAGER("M001", "NOT FOUND MANAGER"),
NOT_VALID_PASSWORD("M002", "NOT VALID PASSWORD"),
NOT_VALID_USER("M003", "NOT VALID USER"),

// REGISTER
DUPLICATE_EMAIL("R001", "Duplicate Email"),
NOT_EQUAL_PASSWORD("R002", "Password 1, 2 Not Equal"),

;
private final String code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

import com.bancow.bancowback.domain.sub.news.entity.News;

import lombok.extern.slf4j.Slf4j;

@ControllerAdvice
Expand Down Expand Up @@ -122,5 +120,62 @@ protected ResponseEntity<ErrorResponse> handlerNewsException(NewsException e) {
final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_FOUND_NEWS);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(TokenAuthorityException.class)
protected ResponseEntity<ErrorResponse> handlerTokenAuthorityException(TokenAuthorityException e) {
log.error("TokenAuthorityException", e);
final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_AUTHORITY);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(TokenAuthoritySuperException.class)
protected ResponseEntity<ErrorResponse> handlerTokenAuthoritySuperException(TokenAuthoritySuperException e) {
log.error("TokenAuthoritySuperException", e);
final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_AUTHORITY_SUPER);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(TokenNotFoundException.class)
protected ResponseEntity<ErrorResponse> handlerTokenException(TokenNotFoundException e) {
log.error("TokenNotFoundException", e);
final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_FOUND_TOKEN);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(ManagerNotFoundException.class)
protected ResponseEntity<ErrorResponse> handlerManagerNotFoundException(ManagerNotFoundException e) {
log.error("ManagerNotFoundException", e);
final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_FOUND_MANAGER);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(ManagerNotValidPasswordException.class)
protected ResponseEntity<ErrorResponse> handlerManagerNotValidPasswordException(ManagerNotValidPasswordException e) {
log.error("ManagerNotValidPasswordException", e);
final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_VALID_PASSWORD);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(ManagerNotValidException.class)
protected ResponseEntity<ErrorResponse> handlerManagerNotValidException(ManagerNotValidException e) {
log.error("ManagerNotValidException", e);
final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_VALID_USER);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(RegisterDuplicateEmailException.class)
protected ResponseEntity<ErrorResponse> handlerRegisterDuplicateEmailException(RegisterDuplicateEmailException e) {
log.error("RegisterDuplicateEmailException", e);
final ErrorResponse response = ErrorResponse.of(ErrorCode.DUPLICATE_EMAIL);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(RegisterNotEqualPasswordException.class)
protected ResponseEntity<ErrorResponse> handlerRegisterNotEqualPasswordException(
RegisterNotEqualPasswordException e) {
log.error("RegisterNotEqualPasswordException", e);
final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_EQUAL_PASSWORD);
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bancow.bancowback.domain.common.exception;

import lombok.Getter;

@Getter
public class ManagerNotFoundException extends RuntimeException {
private ErrorCode managerErrorCode;
private String detailMessage;

public ManagerNotFoundException(ErrorCode managerErrorCode, String detailMessage) {
super(detailMessage);
this.managerErrorCode = managerErrorCode;
this.detailMessage = detailMessage;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bancow.bancowback.domain.common.exception;

import lombok.Getter;

@Getter
public class ManagerNotValidException extends RuntimeException {
private ErrorCode managerErrorCode;
private String detailMessage;

public ManagerNotValidException(ErrorCode managerErrorCode, String detailMessage) {
super(detailMessage);
this.managerErrorCode = managerErrorCode;
this.detailMessage = detailMessage;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bancow.bancowback.domain.common.exception;

import lombok.Getter;

@Getter
public class ManagerNotValidPasswordException extends RuntimeException {
private ErrorCode managerErrorCode;
private String detailMessage;

public ManagerNotValidPasswordException(ErrorCode managerErrorCode, String detailMessage) {
super(detailMessage);
this.managerErrorCode = managerErrorCode;
this.detailMessage = detailMessage;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bancow.bancowback.domain.common.exception;

import lombok.Getter;

@Getter
public class RegisterDuplicateEmailException extends RuntimeException {
private ErrorCode registerErrorCode;
private String detailMessage;

public RegisterDuplicateEmailException(ErrorCode registerErrorCode, String detailMessage) {
super(detailMessage);
this.registerErrorCode = registerErrorCode;
this.detailMessage = detailMessage;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bancow.bancowback.domain.common.exception;

import lombok.Getter;

@Getter
public class RegisterNotEqualPasswordException extends RuntimeException {
private ErrorCode registerErrorCode;
private String detailMessage;

public RegisterNotEqualPasswordException(ErrorCode registerErrorCode, String detailMessage) {
super(detailMessage);
this.registerErrorCode = registerErrorCode;
this.detailMessage = detailMessage;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bancow.bancowback.domain.common.exception;

public class TokenAuthorityException extends TokenNotFoundException {

public TokenAuthorityException(ErrorCode tokenErrorCode, String detailMessage) {
super(tokenErrorCode, detailMessage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bancow.bancowback.domain.common.exception;

public class TokenAuthoritySuperException extends TokenNotFoundException {

public TokenAuthoritySuperException(ErrorCode tokenErrorCode, String detailMessage) {
super(tokenErrorCode, detailMessage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bancow.bancowback.domain.common.exception;

import lombok.Getter;

@Getter
public class TokenNotFoundException extends RuntimeException {
private ErrorCode tokenErrorCode;
private String detailMessage;

public TokenNotFoundException(ErrorCode tokenErrorCode, String detailMessage) {
super(detailMessage);
this.tokenErrorCode = tokenErrorCode;
this.detailMessage = detailMessage;
}

}

0 comments on commit 14cd5f2

Please sign in to comment.