swemon
swemon

Reputation: 5946

Alfresco exception message format

I want to show only my message for alfresco workflow exception. But in alfresco exception message format is that 1. exception.class.name 2. ErrorLogNumber 3. Message

For example, org.alfresco.service.cmr.workflow.WorkflowException: 05130007 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I only want to show 3.Message not 1.exception.class.name and 2.ErrorLogNumber. I can remove ErrorLogNumber from message by adding a custom exception class. But I can't remove 1.exception.class.name from error message. Let me know how to implement that.

Upvotes: 0

Views: 1558

Answers (3)

Cherry
Cherry

Reputation: 33534

The solution is quite simple. Just throw AlfrescoRuntimeException with your message.

throw new AlfrescoRuntimeException("your.message");

In that case you get a message, but loose exception subtyping.

It is really hard to explain in words how I was suprised when saw exception handling in alfresco javaScript code:

        onFormSubmitFailure: function FormManager_onFormSubmitFailure(response)
        {
           var failureMsg = null;
           if (response.json && response.json.message && response.json.message.indexOf("Failed to persist field 'prop_cm_name'") !== -1)
           {
                failureMsg = this.msg("message.details.failure.name");
           }
           else if (response.json && response.json.message && response.json.message.indexOf("PropertyValueSizeIsMoreMaxLengthException") !== -1)
           {
                failureMsg = this.msg("message.details.failure.more.max.length");
           }
           else if (response.json && response.json.message && response.json.message.indexOf("org.alfresco.error.AlfrescoRuntimeException") == 0)
           {  
              var split =  response.json.message.split(/(?:org.alfresco.error.AlfrescoRuntimeException:\s*\d*\s*)/ig);
              if (split && split[1])
              {
                    failureMsg = split[1];
              }
           }
           Alfresco.util.PopupManager.displayPrompt(
           {
              title: this.msg(this.options.failureMessageKey),
              text: failureMsg ? failureMsg : (response.json && response.json.message ? response.json.message : this.msg("message.details.failure"))
           });
        },

As you can see they "catch" class name from java and replace it with message. I hope they provide more extensible way to handle custome exceptions.

P.S. Of course another way is to extend alfresco.js file and add one more if else condition for you exception.

Upvotes: 1

Michał Wróbel
Michał Wróbel

Reputation: 558

I had similar problem as you and failed to trace where this message is created even using debugger, quite tricky. Also anyone on Alfresco forums couldn't help me. I developed a workaround instead of throwing an exception directly in java workflow task, I used a JS validation in form (the way I told you in another post), there I called a java webscript using ajax, which in case of error displayed JS alert box.

Upvotes: 0

shmoula
shmoula

Reputation: 1083

Have you tried to override toString in your exception class? Or maybe to change logger implementation, if output is printed this way.

Upvotes: 0

Related Questions