You can start with com.haulmont.cuba.core.global.validation.CustomValidationException and throw it from your service code. It is translated to JSON errors automatically.
@artamonov thanks, but ValidationException is not so helpfull, some time you need to pass the property name of the field. or maybe other params such as dependency field…
What is the apropriate way to create my own custom exception that will be translated automatically to json with status code?
I have tried to extend CustomValidationException:
@SupportedByClient
public class WebException extends CustomValidationException {
private String errorCode;
private String errorDescription;
public WebException(){
super("");
}
public WebException(String errorCode){
super(errorCode);
this.errorCode = errorCode;
}
public WebException(String errorCode, String errorDescription){
super(errorCode);
this.errorCode = errorCode;
this.errorDescription = errorDescription;
}
//.. getters setters
}
But it is not serialized…
Thanks again!
B.T.W throwing CustomValidationException from the service not serialized as well