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 ba584a4 commit 8a290af
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 38 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.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -14,11 +14,11 @@ public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler {

@Override
public void handleUncaughtException(Throwable e, Method method, Object... params) {
if (e instanceof CoreApiException) {
switch (((CoreApiException) e).getErrorType().getLogLevel()) {
case ERROR -> log.error("CoreApiException : {}", e.getMessage(), e);
case WARN -> log.warn("CoreApiException : {}", e.getMessage(), e);
default -> log.info("CoreApiException : {}", e.getMessage(), e);
if (e instanceof CoreException) {
switch (((CoreException) e).getErrorType().getLogLevel()) {
case ERROR -> log.error("CoreException : {}", e.getMessage(), e);
case WARN -> log.warn("CoreException : {}", e.getMessage(), e);
default -> log.info("CoreException : {}", e.getMessage(), e);
}
}
else {
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;
Expand All @@ -15,12 +15,12 @@ public class ApiControllerAdvice {

private final Logger log = LoggerFactory.getLogger(getClass());

@ExceptionHandler(CoreApiException.class)
public ResponseEntity<ApiResponse<?>> handleCoreApiException(CoreApiException e) {
@ExceptionHandler(CoreException.class)
public ResponseEntity<ApiResponse<?>> handleCoreException(CoreException e) {
switch (e.getErrorType().getLogLevel()) {
case ERROR -> log.error("CoreApiException : {}", e.getMessage(), e);
case WARN -> log.warn("CoreApiException : {}", e.getMessage(), e);
default -> log.info("CoreApiException : {}", e.getMessage(), e);
case ERROR -> log.error("CoreException : {}", e.getMessage(), e);
case WARN -> log.warn("CoreException : {}", e.getMessage(), e);
default -> log.info("CoreException : {}", e.getMessage(), e);
}
return new ResponseEntity<>(ApiResponse.error(e.getErrorType(), e.getData()), e.getErrorType().getStatus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.dodn.springboot.core.domain.ExampleData;
import io.dodn.springboot.core.domain.ExampleResult;
import io.dodn.springboot.core.domain.ExampleService;
import io.dodn.springboot.core.api.support.response.ApiResponse;
import io.dodn.springboot.core.support.response.ApiResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down

This file was deleted.

This file was deleted.

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

public class CoreApiException extends RuntimeException {
public class CoreException extends RuntimeException {

private final ErrorType errorType;

private final Object data;

public CoreApiException(ErrorType errorType) {
public CoreException(ErrorType errorType) {
super(errorType.getMessage());
this.errorType = errorType;
this.data = null;
}

public CoreApiException(ErrorType errorType, Object data) {
public CoreException(ErrorType errorType, Object data) {
super(errorType.getMessage());
this.errorType = errorType;
this.data = data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.dodn.springboot.core.support.error;

public enum 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;

public class ErrorMessage {

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;

public class ApiResponse<S> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.dodn.springboot.core.support.response;

public enum ResultType {

SUCCESS, ERROR

}

0 comments on commit 8a290af

Please sign in to comment.