Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move error codes into their exception types [1004] #1033

Closed
wants to merge 1 commit into from

Conversation

MarkZuber
Copy link
Contributor

I've started working on [1004] for moving MsalError error constants into their respective exception classes.

Looking through the first run of this change, I'm actually not a fan of this approach. I believe we should go the other way and remove the constants from the exception class and have everything in MsalError (with corresponding messages in MsalErrorMessage)

  • Not all MsalError values are used in an MsalException, sometimes it's a response value or other usage.
  • A few of the errors cross boundaries and are used in ClientException and ServiceException
  • We throw MsalException itself in a few cases. I'm not sure why/how that makes sense and what this hierarchy is providing for customers
  • Now the error codes are in one of 3 classes (MsalException, MsalClientException, MsalErrorException) but the messages are all in one file (MsalErrorMessage). It's not always clear which place to pull the constant from. They were ALL in MsalError before.

Please comment on this feedback as well as what we should do with the errors that aren't used on any of the exceptions if you still believe we should go this way. Should they just go into MsalException (even though they'll never be attached to an exception)?

#1004

@@ -86,7 +86,7 @@ public AdfsOpenIdConfigurationEndpointManager(IServiceBundle serviceBundle)
a.Href.Equals(resource, StringComparison.OrdinalIgnoreCase)) == null)
{
throw MsalExceptionFactory.GetClientException(
MsalError.InvalidAuthority,
MsalServiceException.InvalidAuthority,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be client here.

@@ -60,7 +60,7 @@ public AuthorityEndpointResolutionManager(IServiceBundle serviceBundle, bool sho
if (authorityInfo.AuthorityType == AuthorityType.Adfs && string.IsNullOrEmpty(userPrincipalName))
{
throw MsalExceptionFactory.GetClientException(
MsalError.UpnRequired,
MsalServiceException.UpnRequired,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client.

@@ -82,7 +82,7 @@ public class MsalClientException : MsalException
/// implementing chrome tabs is missing on the Android phone (that's only an example: this exception can apply to other
/// platforms as well)
/// </summary>
public const string AuthenticationUiFailedError = "authentication_ui_failed";
public const string AuthenticationUiFailed = "authentication_ui_failed";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this be a breaking change? w/the name change?


// todo: not used anywhere
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just remove all this?

MsalErrorMessage.NonParsableOAuthError,
response);
}
catch (Exception ex)
{
exceptionToThrow = MsalExceptionFactory.GetServiceException(MsalError.UnknownError, response.Body, response, ex);
exceptionToThrow = MsalExceptionFactory.GetServiceException(MsalException.UnknownError, response.Body, response, ex);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be service?

Copy link
Collaborator

@jennyf19 jennyf19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐑 🐺

@jennyf19
Copy link
Collaborator

jennyf19 commented Apr 2, 2019

@mzuber@microsoft.com so i went too fast and didn't read this before reviewing. I agree. I like having MsalError and doing MsalExceptionFactory.GetClientException or GetServiceException. This is much clearer, and, as you point out, will be easier to maintain moving forward as all the consts will be in one place.

@jmprieur
Copy link
Contributor

jmprieur commented Apr 3, 2019

How would this affect the DevEx @MarkZuber and @jennyf19 ?

for instance, how would this transform the code in https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Username-Password-Authentication#how-to-use-it ?
(which BTW does not use the constants in the Exceptions … so … well …

If we do as you propose, @MarkZuber, let's make sure that the XML comments tell customers if an error message can be thrown in a client or service exception.

Finally, this discussion is also related to the Apple team's proposal: MSAL error handling in iOS. Apparently they prefer option 6.

@@ -60,7 +60,7 @@ public static void Validate(Uri redirectUri, bool usesSystemBrowser = false)
Constants.DefaultRedirectUri.Equals(redirectUri.AbsoluteUri, StringComparison.OrdinalIgnoreCase))
{
throw MsalExceptionFactory.GetClientException(
Copy link
Member

@bgavrilMS bgavrilMS Apr 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good moment to delete the exception factory.

@MarkZuber
Copy link
Contributor Author

How would this affect the DevEx @MarkZuber and @jennyf19 ?

for instance, how would this transform the code in https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Username-Password-Authentication#how-to-use-it ?
(which BTW does not use the constants in the Exceptions … so … well …

If we do as you propose, @MarkZuber, let's make sure that the XML comments tell customers if an error message can be thrown in a client or service exception.

Finally, this discussion is also related to the Apple team's proposal: MSAL error handling in iOS. Apparently they prefer option 6.

So for us, option 6 would look like moving all error types into MsalError.cs which is also what I'm proposing. Splitting them into the different exceptions, i feel, looks odd in this PR.

@jmprieur
Copy link
Contributor

jmprieur commented Apr 4, 2019

@MarkZuber : I'm a bit confused by this PR.
Do we agree that we want to move all the errors in MsalError.cs ?
I see that they are also added to the Exception classes?

@MarkZuber
Copy link
Contributor Author

@MarkZuber : I'm a bit confused by this PR.
Do we agree that we want to move all the errors in MsalError.cs ?
I see that they are also added to the Exception classes?

I have two PRs.

@MarkZuber
Copy link
Contributor Author

Officially aborting this PR. The way we're going is this: #1039

@MarkZuber MarkZuber closed this Apr 4, 2019
@MarkZuber MarkZuber deleted the markzuber/errorcodes branch April 4, 2019 15:31
@jmprieur
Copy link
Contributor

jmprieur commented Apr 4, 2019

Thanks for clarifying, @MarkZuber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants