(JAVA) How to treat Exception with spring?

Asked

Viewed 104 times

0

In my model I declared this code to be unique.

@Column(unique=true, name = "codigo") private long codigo;

At the time it is displayed in the api and I inform equal codes for two employees appears to error message, how can I treat it ?

I tried to do so :


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

@ResponseStatus(value = HttpStatus.NOT_FOUND)
public class ConstraintViolationException extends RuntimeException{
    private static final long serialVersionUID = 1L;
    
    public ConstraintViolationException(String msg) {
        super(msg);
    }

But it didn’t work, what’s missing in my code? I use java and spring boot.

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.