日志处理

This commit is contained in:
zhangchenbiao
2023-06-16 11:38:17 +08:00
parent df49f4a71f
commit a85a51adf8
2 changed files with 6 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ package com.cool.store.handler;
import com.cool.store.exception.ApiException;
import com.cool.store.exception.ServiceException;
import com.cool.store.response.error.ErrorResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -15,23 +16,27 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
* @Description: 自定义异常处理
* @date 2023-06-13 19:42
*/
@Slf4j
@RestControllerAdvice
public class CustomExceptionHandler {
@ExceptionHandler(value = ServiceException.class)
public ResponseEntity<ErrorResponse> handleCustomException(ServiceException e) {
log.error(e.getMessage(), e);
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(value = ApiException.class)
public ResponseEntity<ErrorResponse> handleCustomException(ApiException e) {
log.error(e.getMessage(), e);
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(value = Exception.class)
public ResponseEntity<ErrorResponse> handleException(Exception e) {
log.error(e.getMessage(), e);
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}

View File

@@ -41,7 +41,7 @@
</encoder>
</appender>
<logger name="com.cool.store.mapper" level="DEBUG" additivity="true" />
<logger name="com.cool.store.mapper" level="DEBUG" additivity="true" />
<!--灰度、线上、预防 不输出到console-->
<springProfile name="hd,online,pre">
<root level="info">