Skip to content

Commit

Permalink
feat(#53): converted common Exception classes java to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
KimDoubleB committed Jan 17, 2023
1 parent c1dc055 commit e03631d
Show file tree
Hide file tree
Showing 27 changed files with 104 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void sendUserRegisterMessage(final BaseUserDtoV1 baseUser, final String r
baseUser.getCreatedAt()))))
)));
} catch (IOException | SlackApiException e) {
throw new SlackException(e.getMessage());
throw new SlackException();
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package site.archive.common.exception

import java.util.Optional

open class BaseException : RuntimeException {

val exceptionCode: ExceptionCode
private var additionalMessage: String? = null

constructor(exceptionCode: ExceptionCode) : super(exceptionCode.message) {
this.exceptionCode = exceptionCode
}

constructor(additionalMessage: String?, exceptionCode: ExceptionCode) : super("${exceptionCode.message} : $additionalMessage") {
this.exceptionCode = exceptionCode
this.additionalMessage = additionalMessage
}

fun getAdditionalMessage(): Optional<String> {
return Optional.ofNullable(additionalMessage)
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package site.archive.common.exception;
package site.archive.common.exception

import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.http.HttpStatus;
import com.fasterxml.jackson.annotation.JsonFormat
import org.springframework.http.HttpStatus

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ExceptionCode {
enum class ExceptionCode(val status: HttpStatus,
val code: String,
val message: String) {

// Global
NO_VALUE(HttpStatus.BAD_REQUEST, "Global001", "필요한 값이 없거나 전달된 값에 문제가 있습니다."),
Expand All @@ -16,6 +18,7 @@ public enum ExceptionCode {

// Infra
FAILED_FILE_UPLOAD(HttpStatus.INTERNAL_SERVER_ERROR, "Infra001", "(File IO) Failed to stream of upload file"),
SLACK_MESSAGE_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "Infra002", "Sending slack message failed"),

// Common
DUPLICATED_RESOURCE(HttpStatus.CONFLICT, "Common001", "이미 존재하는 리소스 입니다"),
Expand All @@ -34,26 +37,4 @@ public enum ExceptionCode {
AUTHENTICATION_FAILURE(HttpStatus.UNAUTHORIZED, "Security003", "인증에 실패하였습니다"),
;

private final HttpStatus status;
private final String code;
private final String message;

ExceptionCode(final HttpStatus status, final String code, final String message) {
this.status = status;
this.message = message;
this.code = code;
}

public String getMessage() {
return this.message;
}

public String getCode() {
return code;
}

public HttpStatus getStatus() {
return status;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package site.archive.common.exception.common

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class DuplicateFieldValueException(duplicatedField: String, duplicatedValue: String) :
BaseException(
"'$duplicatedValue'은 중복된 $duplicatedField 입니다. 다른 $duplicatedField 을 사용해주세요",
ExceptionCode.DUPLICATED_FIELD_VALUE
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package site.archive.common.exception.common

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class DuplicateResourceException(duplicatedResource: String) : BaseException(duplicatedResource, ExceptionCode.DUPLICATED_RESOURCE)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package site.archive.common.exception.common

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class ResourceNotFoundException(notFoundMessage: String) : BaseException(notFoundMessage, ExceptionCode.NOT_FOUND_RESOURCE)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package site.archive.common.exception.common

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class UnauthorizedResourceException(message: String) : BaseException(message, ExceptionCode.UNAUTHORIZED_RESOURCE)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package site.archive.common.exception.infra

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class FileInvalidException : BaseException(ExceptionCode.FAILED_FILE_UPLOAD)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package site.archive.common.exception.infra

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class SlackException : BaseException(ExceptionCode.SLACK_MESSAGE_FAILED)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package site.archive.common.exception.security

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class InvalidTokenException : BaseException(ExceptionCode.INVALID_TOKEN)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package site.archive.common.exception.security

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class TokenNotFoundException : BaseException(ExceptionCode.TOKEN_NOT_FOUND)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package site.archive.common.exception.user

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class LoginFailException(message: String) : BaseException(message, ExceptionCode.LOGIN_FAIL)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package site.archive.common.exception.user

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class OAuthRegisterFailException(oAuthProviderRegistrationId: String, message: String) :
BaseException("$oAuthProviderRegistrationId : $message", ExceptionCode.REGISTER_FAIL)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package site.archive.common.exception.user

import site.archive.common.exception.BaseException
import site.archive.common.exception.ExceptionCode

class OAuthUserHasNotPasswordException : BaseException(ExceptionCode.OAUTH_USER_NOT_HAS_PASSWORD) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected ResponseEntity<ExceptionResponse> handleAuthenticationException(Authen
@ExceptionHandler(BaseException.class)
protected ResponseEntity<ExceptionResponse> handleBaseException(final BaseException e) {
log.error("BaseException ", e);
final var errorCode = e.getErrorCode();
final var errorCode = e.getExceptionCode();
final var response = e.getAdditionalMessage()
.map(additionalMessage -> ExceptionResponse.of(errorCode, additionalMessage))
.orElse(ExceptionResponse.of(errorCode));
Expand Down

0 comments on commit e03631d

Please sign in to comment.