This commit is contained in:
jiangh277
2025-07-22 23:00:39 +08:00
commit f8fb9b561c
59 changed files with 2456 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package com.timeline.handler;
import com.timeline.exception.CustomException;
import com.timeline.response.ResponseEntity;
import com.timeline.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());
}
}