Skip to content

Commit

Permalink
perf: 优化404错误
Browse files Browse the repository at this point in the history
  • Loading branch information
jamebal committed Mar 19, 2024
1 parent c6f18ae commit 3bb163e
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
import com.jmal.clouddisk.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.ClientAbortException;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindException;
import org.springframework.web.ErrorResponse;
import org.springframework.web.ErrorResponseException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.context.request.async.AsyncRequestTimeoutException;
import org.springframework.web.servlet.resource.NoResourceFoundException;


/**
Expand Down Expand Up @@ -60,4 +65,11 @@ public ResponseResult<Object> exceptionHandler(MethodArgumentNotValidException e
public ResponseResult<Object> exceptionHandler(BindException e) {
return ResultUtil.error(ExceptionType.MISSING_PARAMETERS.getCode(), e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
}

@ExceptionHandler(NoResourceFoundException.class)
@ResponseBody
@ResponseStatus(HttpStatus.NOT_FOUND)
public ErrorResponse handleNoResourceException() {
return new ErrorResponseException(HttpStatus.NOT_FOUND);
}
}

0 comments on commit 3bb163e

Please sign in to comment.