-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Closed as not planned
Closed as not planned
Copy link
Labels
status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Description
I just updated to latest springboot 3.2.1 and now I have compiler errors.
cannot find symbol
1440385 [ERROR] symbol: variable ERROR_ATTRIBUTE
1440385 [ERROR] location: interface org.springframework.boot.web.servlet.error.ErrorAttributes
I'm using this in my error handler:
@Slf4j
@RestControllerAdvice
public class GlobalDefaultExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(Throwable.class)
void defaultErrorHandler(final Throwable e, final HttpServletRequest request, final HttpServletResponse response) throws IOException {
log.error("An unchecked error '{}' happens with message '{}' for method '{}', uri '{}', headers '{}'",
e.getClass(), e.getMessage(), request.getMethod(), request.getRequestURI(), new ServletServerHttpRequest(request).getHeaders(), e);
if (!response.isCommitted()) {
response.sendError(HttpStatus.BAD_REQUEST.value(), collectMessages(e));
}
request.setAttribute(ErrorAttributes.ERROR_ATTRIBUTE, e);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
static String collectMessages(final Throwable e) {
return appendMessages(e, new StringBuilder(128), 2).toString();
}
static StringBuilder appendMessages(@Nullable final Throwable e, final StringBuilder sb, final int goDeeperCount) {
if (goDeeperCount <= 0 || e == null) {
return sb;
}
if (e instanceof IllegalStateException || e instanceof IllegalArgumentException) {
if (sb.length() > 0) {
sb.append(" - caused by -> ");
}
sb.append(e.getMessage());
}
return appendMessages(e.getCause(), sb, goDeeperCount - 1);
}
@ExceptionHandler(ConstraintViolationException.class)
void handleConstraintViolationException(final ConstraintViolationException e, final HttpServletRequest request,
final HttpServletResponse response) throws IOException {
log.error("An api validation error happens '{}'", e.getMessage(), e);
response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage());
request.setAttribute(ErrorAttributes.ERROR_ATTRIBUTE, e);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
@ExceptionHandler(TooManyConfigurationsException.class)
void handleTooManyConfigurationsException(final TooManyConfigurationsException e, final HttpServletRequest request,
final HttpServletResponse response)
throws IOException {
log.error("Limit reached", e);
response.sendError(HttpStatus.TOO_MANY_REQUESTS.value());
response.setHeader("X-RateLimit-Limit", Integer.toString(e.getMaxConfigurations()));
request.setAttribute(ErrorAttributes.ERROR_ATTRIBUTE, e);
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
}
May this code is obsolete or wrong ... but anyway I think such a breaking change could not be part of a patch release.
Kind regards
Andreas
Metadata
Metadata
Assignees
Labels
status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid