0

We are upgrading springboot from 2.3.12 RELEASE to 2.7.12 version. After the upgrade we face the following issues in custom exception controller class named SampleExceptionController

SampleExceptionController.java:36: error:incompatible types:boolean cannot be converted to ErrorAttributeOptions 

The code snippet from SampleExceptionController is

@RestController
public class SampleExceptionController extends BasicErrorController{

@PostMapping
private ResponseEntity<ErrorMessage> appExceptionHandler(HttpServletRequest request){

36: Map<String, Object> body = getErrorAttributes(request, isIncludeStackTrace(request,MediaType.APPLICATION.JSON));
  
String errMsg = String.valueOf(body.get("message"));
int result = (int)body.get("status");

return ResonseEntity.status(HttpStatus.valueOf(result)).body(new ErrorMessage(result,errMsg));

}

Here isIncludeStackTrace method returns boolean and it is a method present in BasicErrorController class

getErrorAttributes method is present in AbstractErrorController class and the implementation is

protected Map<String, Object> getErrorAttributes(HttpServletRequest request, ErrorAttributeOptions options){ }

But the same code was working fine before springboot upgrade

I could not get what is the problem, can anyone help here?

Thanks

LearnToCode
  • 169
  • 1
  • 5
  • 19

1 Answers1

0

I have removed isIncludeStackTrace method and modified the code as below

ErrorAttributeOptions options = ErrorAttributeOptions
    .defaults()
    .including(ErrorAttributeOptions.Include.STACK_TRACE);
Map<String, Object> body = getErrorAttributes(request, options);

Reference Link - Problem with cutomizing ErrorAttributeOptions in Spring Reactive

LearnToCode
  • 169
  • 1
  • 5
  • 19