How to change error.message value?

I'm implementing error handling on a proxy, and am using a `RaiseFault` policy to trigger an error based on the response content from a backend server. I'm using a `JavaScript` policy to examine the response, and setting some variables that the `RaiseFault` policy is using to populate the `ReasonPhrase` element. This all works fine, but in the `PostClientFlow`, there's a `MessageLogging` policy for logging all errors, and it includes `error.message` as part of the log message, and this gets set to `Raising Fault. Fault name : <name of RaiseFault policy>` which is not ideal. Is there any way to change this string? I've tried using `FaultRules`, and adding another JS policy in there to explicitly set the value, but that doesn't stick.

Solved Solved
0 2 331
1 ACCEPTED SOLUTION

I think error.message may be a readonly variable; that's why your efforts at overriding it in a JS call may be failing.

The MessageLogging policy. . . .. which uses error.message .... Can you modify it so that it *does not* use error.message?

Maybe use a different variable to hold the message you want to log.

You might need another policy in front of the MessageLogging policy to examine the "alternative" override variable name, and if that one is not set, then just fallback to error.message.

Something like this in pseudo code:

if (override_error_message is null)  
   if (error.message is not null)
      set override_error_message = error.message

And then in <essageLogging, refer to override_error_message.

Would that work?

View solution in original post

2 REPLIES 2

I think error.message may be a readonly variable; that's why your efforts at overriding it in a JS call may be failing.

The MessageLogging policy. . . .. which uses error.message .... Can you modify it so that it *does not* use error.message?

Maybe use a different variable to hold the message you want to log.

You might need another policy in front of the MessageLogging policy to examine the "alternative" override variable name, and if that one is not set, then just fallback to error.message.

Something like this in pseudo code:

if (override_error_message is null)  
   if (error.message is not null)
      set override_error_message = error.message

And then in <essageLogging, refer to override_error_message.

Would that work?

Thanks for the idea! This almost works, but my logging policy is in the `PostClientFlow`, so I can't use a JS policy in there. I believe this could be achieved by using `FaultRules` and handling things in that flow, but for simplicity's sake, I just set the error detail to a new variable, and included that in the log message. One other thing I tried was using default values in the message template, i.e. `errorMessage={customErrorMessage:error.message}` but you can't use variables as defaults (which does make sense).