Retrieve oAuth error.cause in JS

I am trying to retrieve the oauth error cause in the JavaScript policy. I can see the error.cause property populated in the trace (refer the below image) but not able to fetch it using context.getVariable("error.cause") and context.getVariable("oauthV2.OA_generateToken.error.cause"). What is the best way to get the oAuth error.cause in JS?

2614-trace.jpg

1 7 188
7 REPLIES 7

@Mahammad Feroz , Where do you see above issue ? In onPrem / Cloud ?

@Anil Sagar, it's in cloud.

@Mahammad Feroz ,

As far as i know , there is no flow variable called "error.cause" . If you can see in trace, it's a property. You can access error message using flow variable "error.message". For more details refer documentation here.

Please find proxy code that works for me in cloud & attached screenshot that prints error message in trace using above flow variable.

2616-screen-shot-2016-05-03-at-115113-am.png

2615-notar.png

no-target-rev1-2016-05-03.zip

Keep us posted, if you still see any issue.

@Anil Sagar, it works fine for verify access token operation as it's populating the error property with meaningful message which can be retrieved using error.message in JS. But in case of generate access token operation the error property is just giving "invalid_client" error where as error.cause is giving the actual message as showed in my earlier attachment. Hence is there anyway to get the actual error message ("Client identifier is required")?

@Mahammad Feroz , Yes, I can able to reproduce same. I am afraid it's not available in flow variables to access same. From trace documentation here,

Properties represent the internal state of the API proxy. Shouldn't be confused with variables.

"error.cause" is a property not a flow variable. Agree, error description should be more informative. I will take this request with Engineering team. Thank you for highlighting same.

@Mahammad Feroz , You can quickly implement a workaround by using a simple raise fault policy with a condition that checks for client identifier present or not & sets response message to desired text. Hope it helps.

@Anil Sagar, it will not work for me as oAuth returns the same fault code for different error messages. For ex: fault code: invalid_client is being returned for the error messages: Client identifier is required, ClientId is Invalid & Client credentials are invalid. Similarly fault code: invalid_request is also being used for multiple oAuth error messages. Any other thoughts to handle this?