Skip to content

Commit

Permalink
Repackaged errors and responses for the core.
Browse files Browse the repository at this point in the history
  • Loading branch information
geminiKim committed Sep 17, 2024
1 parent c671e73 commit 8ac5c5e
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.dodn.springboot.core.api.config

import io.dodn.springboot.core.api.support.error.CoreApiException
import io.dodn.springboot.core.support.error.CoreException
import org.slf4j.LoggerFactory
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler
import org.springframework.boot.logging.LogLevel
Expand All @@ -10,11 +10,11 @@ class AsyncExceptionHandler : AsyncUncaughtExceptionHandler {
private val log = LoggerFactory.getLogger(javaClass)

override fun handleUncaughtException(e: Throwable, method: Method, vararg params: Any?) {
if (e is CoreApiException) {
if (e is CoreException) {
when (e.errorType.logLevel) {
LogLevel.ERROR -> log.error("CoreApiException : {}", e.message, e)
LogLevel.WARN -> log.warn("CoreApiException : {}", e.message, e)
else -> log.info("CoreApiException : {}", e.message, e)
LogLevel.ERROR -> log.error("CoreException : {}", e.message, e)
LogLevel.WARN -> log.warn("CoreException : {}", e.message, e)
else -> log.info("CoreException : {}", e.message, e)
}
} else {
log.error("Exception : {}", e.message, e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.dodn.springboot.core.api.controller

import io.dodn.springboot.core.api.support.error.CoreApiException
import io.dodn.springboot.core.api.support.error.ErrorType
import io.dodn.springboot.core.api.support.response.ApiResponse
import io.dodn.springboot.core.support.error.CoreException
import io.dodn.springboot.core.support.error.ErrorType
import io.dodn.springboot.core.support.response.ApiResponse
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.boot.logging.LogLevel
Expand All @@ -14,12 +14,12 @@ import org.springframework.web.bind.annotation.RestControllerAdvice
class ApiControllerAdvice {
private val log: Logger = LoggerFactory.getLogger(javaClass)

@ExceptionHandler(CoreApiException::class)
fun handleCoreApiException(e: CoreApiException): ResponseEntity<ApiResponse<Any>> {
@ExceptionHandler(CoreException::class)
fun handleCoreException(e: CoreException): ResponseEntity<ApiResponse<Any>> {
when (e.errorType.logLevel) {
LogLevel.ERROR -> log.error("CoreApiException : {}", e.message, e)
LogLevel.WARN -> log.warn("CoreApiException : {}", e.message, e)
else -> log.info("CoreApiException : {}", e.message, e)
LogLevel.ERROR -> log.error("CoreException : {}", e.message, e)
LogLevel.WARN -> log.warn("CoreException : {}", e.message, e)
else -> log.info("CoreException : {}", e.message, e)
}
return ResponseEntity(ApiResponse.error(e.errorType, e.data), e.errorType.status)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package io.dodn.springboot.core.api.controller.v1

import io.dodn.springboot.core.api.controller.v1.request.ExampleRequestDto
import io.dodn.springboot.core.api.controller.v1.response.ExampleResponseDto
import io.dodn.springboot.core.api.support.response.ApiResponse
import io.dodn.springboot.core.domain.ExampleData
import io.dodn.springboot.core.domain.ExampleService
import io.dodn.springboot.core.support.response.ApiResponse
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.dodn.springboot.core.api.support.error
package io.dodn.springboot.core.support.error

class CoreApiException(
class CoreException(
val errorType: ErrorType,
val data: Any? = null,
) : RuntimeException(errorType.message)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.dodn.springboot.core.support.error

enum class ErrorCode {
E500,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.dodn.springboot.core.api.support.error
package io.dodn.springboot.core.support.error

data class ErrorMessage private constructor(
val code: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.dodn.springboot.core.api.support.error
package io.dodn.springboot.core.support.error

import org.springframework.boot.logging.LogLevel
import org.springframework.http.HttpStatus
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.dodn.springboot.core.api.support.response
package io.dodn.springboot.core.support.response

import io.dodn.springboot.core.api.support.error.ErrorMessage
import io.dodn.springboot.core.api.support.error.ErrorType
import io.dodn.springboot.core.support.error.ErrorMessage
import io.dodn.springboot.core.support.error.ErrorType

data class ApiResponse<T> private constructor(
val result: ResultType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.dodn.springboot.core.support.response

enum class ResultType {
SUCCESS,
ERROR,
}

0 comments on commit 8ac5c5e

Please sign in to comment.