Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate Interceptor error message not showing in 1905 Backoffice

public class DefaultCountValidationInterceptor implements ValidateInterceptor
{
    @Override
    public void onValidate(final Object object, final InterceptorContext interceptorContext) throws InterceptorException
    {
        if (object instanceof BaseStoreModel)
        {
            final BaseStoreModel baseStoreModel = (BaseStoreModel) object;
            if (baseStoreModel.getCount() < 0 || baseStoreModel.getCount() > 100)
            {
                throw new InterceptorException("Count should be between 0 and 100");
            }
        }
    }
}

Interceptor Configuration:

<bean id="defaultCountValidationInterceptor"
        class="se.istone.hybris.maersk.core.interceptors.DefaultCountValidationInterceptor " />
    <bean id="defaultCountValidationInterceptorMapping"
        class="de.hybris.platform.servicelayer.interceptor.impl.InterceptorMapping">
        <property name="interceptor"
            ref="defaultCountValidationInterceptor" />
        <property name="typeCode" value="BaseStore" />
    </bean>

Validation error message is displaying correctly in Hybris5.4 HMC, but its not workinig in Hybris 6.7(1905) Backoffice enter image description here

like image 359
Jagadeesh Kumar Avatar asked Dec 06 '25 05:12

Jagadeesh Kumar


1 Answers

You are always getting default message due OOTB code in ModelSavingExceptionTranslationHandler.toString().

public class ModelSavingExceptionTranslationHandler extends ModelExceptionTranslationHandler {
    public static final String I18N_UNEXPECTED_UPDATE_ERROR = "unexpected.update.error";

    public boolean canHandle(Throwable exception) {
        return exception instanceof ModelSavingException
                || exception instanceof ObjectSavingException && exception.getCause() instanceof ModelSavingException;
    }

    public String toString(Throwable exception) {
        return this.getLabelByKey("unexpected.update.error");
    }
}

When you are throwing InterceptorException Hybris internally throws ModelSavingException with your InterceptorException as Cause.

Backoffice exception are handled by ExceptionTranslationService, which contain list of Handlers to handle different kinds of Exceptions. For ModelSavingException, ModelSavingExceptionTranslationHandler is used.

Since OOTB Handler is straight up displaying default message, you can either override this class or you can create your own Exception Translation Handler and add it in the handlers list.

Documentation -> https://help.sap.com/viewer/5c9ea0c629214e42b727bf08800d8dfa/1905/en-US/8bc9570b86691014a901c290d2c5f107.html

like image 83
Zedex7 Avatar answered Dec 09 '25 06:12

Zedex7