<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Validate Interceptor error message not show in Backoffice in CRM and CX Q&amp;A</title>
    <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204613#M421617</link>
    <description>&lt;P&gt;To solve this, we replaced the default ModelSavingExceptionTranslationHandler with our own implementation:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;/**
 * Exception translation handler that output the exception reason. This is needed because the SAP Commerce
 * Handler ({@link de.hybris.platform.platformbackoffice.services.handlers.ModelSavingExceptionTranslationHandler})
 * will only output a generic message that "something is wrong".
 */
public class CustomBackofficeExceptionTranslationsHandler implements ExceptionTranslationHandler {
  @Override
  public boolean canHandle(Throwable throwable) {
    return true;
  }

  @Override
  public String toString(Throwable throwable) {
    StringBuilder exceptionText = new StringBuilder();
    if (StringUtils.isNotEmpty(throwable.getMessage())) {
      exceptionText.append(throwable.getMessage());
    } else {
      exceptionText.append(throwable.toString()).append(" ").append(throwable.getClass());
    }
    return exceptionText.toString();
  }
}
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To register it, the following bean is needed:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;alias name="customPlatformBackofficeExceptionTranslationStrategiesExtender" alias="platformBackofficeExceptionTranslationStrategiesExtender"/&amp;gt;
&amp;lt;cng:list-extender id="customPlatformBackofficeExceptionTranslationStrategiesExtender" property="exceptionHandlers" bean="exceptionTranslationService"&amp;gt;
  &amp;lt;cng:add value-type="com.hybris.cockpitng.service.ExceptionTranslationHandler"&amp;gt;
    &amp;lt;bean class="ch.your.package.path.CustomBackofficeExceptionTranslationsHandler" /&amp;gt;
  &amp;lt;/cng:add&amp;gt;
&amp;lt;/cng:list-extender&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Apr 2021 10:49:55 GMT</pubDate>
    <dc:creator>janbu</dc:creator>
    <dc:date>2021-04-07T10:49:55Z</dc:date>
    <item>
      <title>Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaq-p/12204603</link>
      <description>&lt;P&gt;Hi, I have created a Validate Interceptor on an my product&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;public class MyProductValidatorInterceptor implements ValidateInterceptor
{
  @Override
  public void onValidate(final Object model, final InterceptorContext ctx) throws InterceptorExceptio
 {
    if (model instanceof MyProductModel 
        &amp;amp;&amp;amp; (ctx.isNew(model) || ctx.isModified(model, ChemicalProductModel.APPROVALSTATUS)))
    {
       final MyProductModel myProductModel = (MyProductModel) model;
       final ArticleApprovalStatus approvalStatus = chemicalProductModel.getApprovalStatus();
       if (ArticleApprovalStatus.APPROVED == approvalStatus)
       {
         throw new InterceptorException("
            The product cannot be saved in approved because there are no mandatory fields");
       }
   }
 }
}
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;but a generic error message is shown in the backoffice&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1789540-save.png" /&gt;&lt;/P&gt;
  &lt;P&gt;how can i show my error message?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Mar 2020 16:15:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaq-p/12204603</guid>
      <dc:creator>crescenzorega</dc:creator>
      <dc:date>2020-03-13T16:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204604#M421608</link>
      <description>&lt;P&gt;I solved by changing the approach, i created a custom TypeConstraint validation&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;public class ApprovedProductValidator implements ConstraintValidator&amp;lt;ApprovedProduct, Object&amp;gt;
{
  @Override
  public boolean isValid(final Object model, final ConstraintValidatorContext arg1)
  {
    if (model instanceof MyProductModel)
    {
      final MyProductModel myProduct = (MyProductModel ) model;
      final ArticleApprovalStatus approvalStatus = chemicalProductModel.getApprovalStatus();
      if (ArticleApprovalStatus.APPROVED == approvalStatus)
      {
        .....
        return false;
      }
    }
    return true;
}
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;now saving is blocked, a message is shown&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1789631-save.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Mar 2020 10:59:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204604#M421608</guid>
      <dc:creator>crescenzorega</dc:creator>
      <dc:date>2020-03-17T10:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204605#M421609</link>
      <description>&lt;P&gt;Hi Crescenzo,&lt;/P&gt;&lt;P&gt;I have the same problem. I used to use the same approach to display custom error messages in the Backoffice ...&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;throw new InterceptorException("my custom error message")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So this seems to be a "new" problem popping up with release 1905.?!&lt;/P&gt;&lt;P&gt;Which version do you use?&lt;/P&gt;&lt;P&gt;Any comments from SAP/Hybris regarding this?&lt;/P&gt;&lt;P&gt;Best regards!&lt;/P&gt;&lt;P&gt;Torsten&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 12:52:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204605#M421609</guid>
      <dc:creator>torsten_lorenz</dc:creator>
      <dc:date>2020-05-14T12:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204606#M421610</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;torsten.lorenz&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;to show custom messages, try to use&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;if (condiction){
 context.disableDefaultConstraintViolation();
 context.buildConstraintViolationWithTemplate("My error message").addConstraintViolation();
 return false;
}
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Crescenzo&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 13:02:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204606#M421610</guid>
      <dc:creator>crescenzorega</dc:creator>
      <dc:date>2020-05-14T13:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204607#M421611</link>
      <description>&lt;P&gt;Thanks a lot, Crescenzo.&lt;/P&gt;&lt;P&gt;But I would like to stick to the original approach since I don't want to change all existing Interceptors (throwing an InterceptorException with custom message) and Unit-Tests in my project.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;public class CustomerXInterceptor implements ValidateInterceptor&amp;lt;CustomerModel&amp;gt; {
    @Override
    public void onValidate(final CustomerModel customer, final InterceptorContext ctx)
            throws InterceptorException {
        if (condition) {
            throw new InterceptorException("my custom error message");
        }
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 May 2020 13:15:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204607#M421611</guid>
      <dc:creator>torsten_lorenz</dc:creator>
      <dc:date>2020-05-14T13:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204608#M421612</link>
      <description>&lt;P&gt;Hi Crescenzo, do you use 1905?&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 13:21:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204608#M421612</guid>
      <dc:creator>torsten_lorenz</dc:creator>
      <dc:date>2020-05-14T13:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204609#M421613</link>
      <description>&lt;P&gt;yes, I use the version 1905.13 with the hybris-cloud-extension-pack-1905.2004&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 13:23:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204609#M421613</guid>
      <dc:creator>crescenzorega</dc:creator>
      <dc:date>2020-05-14T13:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204610#M421614</link>
      <description>&lt;P&gt;The implementation of the method toString on the ModelSavingExceptionTranslationHandler, wich is responsible for resolving the error messages shown in the bakoffice when ever a ModelSavingException occurs, has changed in the release 1905.&lt;/P&gt;&lt;P&gt;Hybris internally catchs all the InterceptorExeptions and then rethrow a ModelSavingException with thos exceptions as cause.&lt;/P&gt;&lt;P&gt;The 1905 release's implementation is as follow :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;public String toString(Throwable exception) {
    return this.getLabelByKey("unexpected.update.error");
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And with this implementation the error message will always the same, no matter what the cause is.&lt;/P&gt;&lt;P&gt;For the sake of comparaison, the implementation in 6.4 shows the detail message of the thrown exception and it is as follow :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;public String toString(Throwable exception) {
    ModelSavingException modelSavingException = (ModelSavingException)(exception instanceof ModelSavingException ? exception : exception.getCause());
    String messageByCause = this.translateByCause(modelSavingException.getCause());
    String message = (String)StringUtils.defaultIfBlank(messageByCause, modelSavingException.getLocalizedMessage());
    return StringUtils.capitalize((String)StringUtils.defaultIfBlank(message, ""));
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This should be a bug because the &lt;A href="https://help.sap.com/viewer/5c9ea0c629214e42b727bf08800d8dfa/1905/en-US/8bc9570b86691014a901c290d2c5f107.html"&gt;documentation&lt;/A&gt; in 1905 still says that the thrown exception's message will be shown, otherwise the documentation is not up to date.&lt;/P&gt;&lt;P&gt;This could be fixed by overriding the ModelSavingExceptionTranslationHandler, but this would affect the hole platform and we don't know yet why the implementation has been changed in the first place. So it is more wise to report a ticket to the SAP support about this.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jul 2020 21:48:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204610#M421614</guid>
      <dc:creator>former_member696639</dc:creator>
      <dc:date>2020-07-19T21:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204611#M421615</link>
      <description>&lt;P&gt;I absolutely agree that this issue should be reported as a bug!&lt;/P&gt;&lt;P&gt;Have you already submitted a ticket?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 07:36:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204611#M421615</guid>
      <dc:creator>S0011572494</dc:creator>
      <dc:date>2020-08-27T07:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204612#M421616</link>
      <description>&lt;P&gt;Hello Fabian,&lt;/P&gt;&lt;P&gt;Sorry for this late response.&lt;/P&gt;&lt;P&gt;No, I didn't submit any ticket yet because our client was ok with the displayed message.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2020 13:31:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204612#M421616</guid>
      <dc:creator>former_member696639</dc:creator>
      <dc:date>2020-10-09T13:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204613#M421617</link>
      <description>&lt;P&gt;To solve this, we replaced the default ModelSavingExceptionTranslationHandler with our own implementation:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;/**
 * Exception translation handler that output the exception reason. This is needed because the SAP Commerce
 * Handler ({@link de.hybris.platform.platformbackoffice.services.handlers.ModelSavingExceptionTranslationHandler})
 * will only output a generic message that "something is wrong".
 */
public class CustomBackofficeExceptionTranslationsHandler implements ExceptionTranslationHandler {
  @Override
  public boolean canHandle(Throwable throwable) {
    return true;
  }

  @Override
  public String toString(Throwable throwable) {
    StringBuilder exceptionText = new StringBuilder();
    if (StringUtils.isNotEmpty(throwable.getMessage())) {
      exceptionText.append(throwable.getMessage());
    } else {
      exceptionText.append(throwable.toString()).append(" ").append(throwable.getClass());
    }
    return exceptionText.toString();
  }
}
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To register it, the following bean is needed:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;alias name="customPlatformBackofficeExceptionTranslationStrategiesExtender" alias="platformBackofficeExceptionTranslationStrategiesExtender"/&amp;gt;
&amp;lt;cng:list-extender id="customPlatformBackofficeExceptionTranslationStrategiesExtender" property="exceptionHandlers" bean="exceptionTranslationService"&amp;gt;
  &amp;lt;cng:add value-type="com.hybris.cockpitng.service.ExceptionTranslationHandler"&amp;gt;
    &amp;lt;bean class="ch.your.package.path.CustomBackofficeExceptionTranslationsHandler" /&amp;gt;
  &amp;lt;/cng:add&amp;gt;
&amp;lt;/cng:list-extender&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 10:49:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204613#M421617</guid>
      <dc:creator>janbu</dc:creator>
      <dc:date>2021-04-07T10:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204614#M421618</link>
      <description>&lt;P&gt;This is helpful, but to override the ModelSavingExceptionTranslationHandler class, the following bean definition is needed. By adding a custom bean you add new TranslationHandler to the list, and since the ExceptionTranslationService returns the first handler's response, it's not guaranteed to see your handler's message if any previous handler can handle the exception.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;alias name="defaultPlatformBackofficeExceptionTranslationStrategiesExtender"
           alias="platformBackofficeExceptionTranslationStrategiesExtender"/&amp;gt;
&amp;lt;cng:list-extender id="defaultPlatformBackofficeExceptionTranslationStrategiesExtender" property="exceptionHandlers"
                   bean="exceptionTranslationService"&amp;gt;
    &amp;lt;cng:add value-type="com.hybris.cockpitng.service.ExceptionTranslationHandler"&amp;gt;
        &amp;lt;bean class="com.custom.backoffice.CustomModelSavingExceptionTranslationHandler"/&amp;gt;
        &amp;lt;bean class="de.hybris.platform.platformbackoffice.services.handlers.ModelRemovalExceptionTranslationHandler"/&amp;gt;
    &amp;lt;/cng:add&amp;gt;
&amp;lt;/cng:list-extender&amp;gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Aug 2021 11:31:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204614#M421618</guid>
      <dc:creator>mansurarisoy</dc:creator>
      <dc:date>2021-08-12T11:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Validate Interceptor error message not show in Backoffice</title>
      <link>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204615#M421619</link>
      <description>&lt;P&gt; don't forget to change alias name and id&lt;/P&gt; 
&lt;PRE&gt;&lt;CODE&gt;&amp;lt;alias name="customPlatformBackofficeExceptionTranslationStrategiesExtender"
           alias="platformBackofficeExceptionTranslationStrategiesExtender"/&amp;gt;
&amp;lt;cng:list-extender id="customPlatformBackofficeExceptionTranslationStrategiesExtender" property="exceptionHandlers"
                   bean="exceptionTranslationService"&amp;gt;
    &amp;lt;cng:add value-type="com.hybris.cockpitng.service.ExceptionTranslationHandler"&amp;gt;
        &amp;lt;bean class="com.nexus2i.deliveryman.calendar.backoffice.logicHandler.CustomBackofficeExceptionTranslationsHandler"/&amp;gt;
        &amp;lt;bean class="de.hybris.platform.platformbackoffice.services.handlers.ModelRemovalExceptionTranslationHandler"/&amp;gt;
    &amp;lt;/cng:add&amp;gt;
&amp;lt;/cng:list-extender&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Sep 2021 11:43:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/crm-and-cx-q-a/validate-interceptor-error-message-not-show-in-backoffice/qaa-p/12204615#M421619</guid>
      <dc:creator>former_member809597</dc:creator>
      <dc:date>2021-09-18T11:43:32Z</dc:date>
    </item>
  </channel>
</rss>

