okta / okta-idx-java

okta-idx-java
https://github.com/okta/okta-idx-java
Other
14 stars 23 forks source link

When exception occurs, no error code is available #439

Closed icsrmontano closed 1 year ago

icsrmontano commented 1 year ago

In case of an error condition, no error code is available via the SDK. Only a generic message. This limitation complicates the customization process.

arvindkrishnakumar-okta commented 1 year ago

This is more of a backend limitation than a SDK limitation, the SDK simply passes through the error that the backend sends.

icsrmontano commented 1 year ago

@arvindkrishnakumar-okta the backend is sending you this. The key and parameter can be used by the developer to provide a better custom message.

"messages": { "type": "array", "value": [ { "message": "'[userProfile.passcode]' cannot be modified.", "i18n": { "key": "api.error.field_immutable", "params": [ "[userProfile.passcode]" ] }, "class": "ERROR" } ] },

icsrmontano commented 1 year ago

@arvindkrishnakumar-okta does my previous comment makes sense to you? Should I open a case?

arvindkrishnakumar-okta commented 1 year ago

@icsrmontano Sorry, I still do not understand the ask from the SDK side. Are you looking to receive a SDK specific error message that is mapped to the backend error message?

icsrmontano commented 1 year ago

Yes. Having the original error code (or any error code) helps the developer to display an error message of his choosing. Rather than displaying the error message the SDK/Okta returns.

From: Arvind Krishnakumar @.> Reply-To: okta/okta-idx-java @.> Date: Tuesday, March 21, 2023 at 1:59 PM To: okta/okta-idx-java @.> Cc: Rafael Montano @.>, Mention @.***> Subject: Re: [okta/okta-idx-java] When exception occurs, no error code is available (Issue #439)

@icsrmontanohttps://github.com/icsrmontano Sorry, I still do not understand the ask from the SDK side. Are you looking to receive a SDK specific error message that is mapped to the backend error message?

— Reply to this email directly, view it on GitHubhttps://github.com/okta/okta-idx-java/issues/439#issuecomment-1478353665, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMILQ2TKVJUIXSY3XUL3Z7TW5HT6PANCNFSM6AAAAAAVEHVPOY. You are receiving this because you were mentioned.Message ID: @.***>

arvindkrishnakumar-okta commented 1 year ago

What does the SDK contain in the response object presently?

icsrmontano commented 1 year ago

We currently get the “message” but not the “key” according to the captured network trace:

"messages": { "type": "array", "value": [ { "message": "'[userProfile.passcode]' cannot be modified.", "i18n": { "key": "api.error.field_immutable", "params": [ "[userProfile.passcode]" ] }, "class": "ERROR" } ] },

From: Arvind Krishnakumar @.> Reply-To: okta/okta-idx-java @.> Date: Tuesday, March 21, 2023 at 3:40 PM To: okta/okta-idx-java @.> Cc: Rafael Montano @.>, Mention @.***> Subject: Re: [okta/okta-idx-java] When exception occurs, no error code is available (Issue #439)

What does the SDK contain in the response object presently?

— Reply to this email directly, view it on GitHubhttps://github.com/okta/okta-idx-java/issues/439#issuecomment-1478480774, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMILQ2RNIHCH2NKR6MW7Y4DW5H72LANCNFSM6AAAAAAVEHVPOY. You are receiving this because you were mentioned.Message ID: @.***>

arvindkrishnakumar-okta commented 1 year ago

@icsrmontano apologies for the delay.

When backend processing exception occurs, the AuthenticationResponse object should contain the list of detailed error messages as sent by the Okta backend. You should be able to see them with authenticationResponse.getErrors(), these errors are raw backend errors.

Let me know if that helps or if I am misunderstanding your ask.

icsrmontano commented 1 year ago

Hi Arvind,

Yes. Whenever an error occurs, we can extract the message but we can’t get the error code/key. The error key is needed because we want to be able to either display a different error message (other than what Okta provides) or display the same message on a different language altogether.

Here’s the original sample of the Okta response to the SDK:

{ "messages": { "type": "array", "value": [ { "message": "'[userProfile.passcode]' cannot be modified.", "i18n": { "key": "api.error.field_immutable", "params": [ "[userProfile.passcode]" ] }, "class": "ERROR" } ] } }

Right now, we can retrieve “[userProfile.passcode]' cannot be modified.” We want to show a different message, but if Okta changes this message at any moment the code breaks. What we want to get is "api.error.field_immutable" so we can map this code to the corresponding message we want to display without depending on Okta not touching the current message.

From: Arvind Krishnakumar @.> Date: Wednesday, June 21, 2023 at 9:16 AM To: okta/okta-idx-java @.> Cc: Rafael Montano @.>, Mention @.> Subject: Re: [okta/okta-idx-java] When exception occurs, no error code is available (Issue #439)

@icsrmontanohttps://github.com/icsrmontano apologies for the delay.

When backend processing exception occurs, the AuthenticationResponse object should contain the list of detailed error messages as sent by the Okta backend. You should be able to see them with authenticationResponse.getErrors(), these errors are raw backend errors.

Let me know if that helps.

— Reply to this email directly, view it on GitHubhttps://github.com/okta/okta-idx-java/issues/439#issuecomment-1600818455, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AMILQ2RW25C35NGTMAWCVIDXMLX3RANCNFSM6AAAAAAVEHVPOY. You are receiving this because you were mentioned.Message ID: @.***>

arvindkrishnakumar-okta commented 1 year ago

Understood, l'll create a PR shortly that addresses this. Thanks for clarifying!

arvindkrishnakumar-okta commented 1 year ago

Released 3.0.5 that contains the fix.