0

i try to display simple error massage for the unavailable resource of my service model by extending my class with RuntimeException but didn't display

TodoService Implementation

@Override
public String retrieveTodoStatusById(Long id) {
    Optional<String> optionalTodo = Optional.ofNullable(todoRepository.findStatusById(id));
    System.out.println("OptionalTodo " +optionalTodo );
    String status = optionalTodo.orElseThrow(TodoNotFoundException::new);
    return  status;
}

TodoNotFoundException

package mang.io.todosrestapi.exceptionhandler;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "Todo not available")
public class TodoNotFoundException extends RuntimeException{

    public TodoNotFoundException(){
    }

public TodoNotFoundException(String message){
    super(message);
}

}

default error with no message is display

Every time i run the exception error message is not display How can display the error message?

1 Answer 1

6

Try to add this line in your application.properties file:

server.error.include-message=always
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.