Skip to content

Commit

Permalink
不将 404 请求解释为异常
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Oct 8, 2024
1 parent c297f7b commit f69b67c
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@RestControllerAdvice
@Slf4j
Expand All @@ -25,6 +26,12 @@ public ResponseEntity<StdResp<Void>> userBannedException(UserBannedException e){
public ResponseEntity<StdResp<Void>> businessExceptionHandler(NotLoginException e){
return ResponseEntity.status(403).body(new StdResp<>(false,"未登录或会话已过期,请转到首页登录", null));
}

@ExceptionHandler(NoResourceFoundException.class)
public ResponseEntity<StdResp<Void>> noResourceFoundException(Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(new StdResp<>(false, "404 Not Found - 资源未找到", null));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<StdResp<Void>> jvmExceptionHandler(Exception e){
log.error("Unexpected exception", e);
Expand Down

0 comments on commit f69b67c

Please sign in to comment.