This commit is contained in:
jiangh277
2025-08-04 16:51:13 +08:00
parent f8fb9b561c
commit eba0eb085e
41 changed files with 451 additions and 73 deletions

View File

@@ -0,0 +1,22 @@
package com.timeline.common.handler;
import com.timeline.common.exception.CustomException;
import com.timeline.common.response.ResponseEntity;
import com.timeline.common.response.ResponseEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(CustomException.class)
public ResponseEntity<String> handleCustomException(CustomException ex) {
return ResponseEntity.error(ex.getCode(), ex.getMessage());
}
@ExceptionHandler(Exception.class)
public ResponseEntity<String> handleGenericException(Exception ex) {
return ResponseEntity.error(ResponseEnum.INTERNAL_SERVER_ERROR.getCode(),
ResponseEnum.INTERNAL_SERVER_ERROR.getMessage() + ": " + ex.getMessage());
}
}