小编Ang*_*izC的帖子

Spring Boot @ResponseStatus not returning HTTP message

I've a problem returning HTTP Messages when an exception is thrown. I'm using @ResponseStatus annotation to handle the HTTP Status code, it shows ok but the message is ignored.

Custom Exception:

@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR, reason = "An error ocurred while trying to 
retrieve the instruments.")
public class InstrumentsNotFoundException extends RuntimeException { 

private static final Logger logger = LoggerFactory.getLogger(InstrumentsNotFoundException.class);

public InstrumentsNotFoundException(String errorMessage) {
    super(errorMessage);
    logger.error(errorMessage);
}
Run Code Online (Sandbox Code Playgroud)

Controller:

@GetMapping({ "/portfolio/" })
public List<Instrument> getAll() {
    try {
        List<Instrument> instruments= portfolioYieldProcessor.getPortfolio();
        return instruments; …
Run Code Online (Sandbox Code Playgroud)

error-handling spring-mvc httpresponse spring-boot

4
推荐指数
1
解决办法
1926
查看次数