question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Offer specific Exceptions instead of generic MsalServiceException

See original GitHub issue

Is your feature request related to a problem? Please describe. Currently there are only two exception types. MsalClientException, MsalServiceException.

All further information, which exact error case is present, are embedded in long magic strings.

This makes the coding very complex and error-prone. Furthermore, it actually contradicts the .NET design recommendation that specific exceptions and no generic exceptions should be thrown. https://docs.microsoft.com/en-us/dotnet/standard/exceptions/ https://docs.microsoft.com/en-us/dotnet/standard/exceptions/how-to-use-specific-exceptions-in-a-catch-block

In addition, it is very time-consuming to analyze errors in log systems, e.g. Application Insights, on the basis of their texts/exception messages and not on the basis of their types.

Describe the solution you’d like Please provide specific exceptions.

Example: when client credentials expire (its secrets), you just get a MsalServiceException with a very long text.

Just provide a e.g. MsalClientCredentialsExpiredException (Can inherit from MsalServiceException to stay compatible with existing code) with additional properties (which client id). This makes programming more secure and we don’t need magic strings anymore.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:9
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
BenjaminAbtcommented, Sep 1, 2022

are not guaranteed to be stable by AAD.

This is the problem that makes so much existing code buggy - and often this is critical code because it’s all about identity. At the end of the day, it’s Microsoft that can plan the behavior. We as consumers of this library don’t notice until it goes bang. This is depressing - and does not create trust.

Microsoft has to orchestrate that. No one else can do that. Other identity providers get this right, too. This is an identity system. We as developers and customers must be able to trust AAD. The experience has to be better.

With other things, the community can fix such deficits itself, because the errors are stable (e.g. https://github.com/Giorgi/EntityFramework.Exceptions which solves the generic exception behavior of EFCore). But in this case, Microsoft has to fix it.

0reactions
bgavrilMScommented, Sep 1, 2022

Got it, the technical solution is not that complicated. The problem here is that the suberrors (https://docs.microsoft.com/en-us/azure/active-directory/develop/reference-aadsts-error-codes#aadsts-error-codes) are not guaranteed to be stable by AAD.

We can provide typed exceptions for the 8 big error codes (invalid_request, invalid_grant etc.). we already provide MsalUiRequiredException for 2 of them.

CC @jmprieur

Read more comments on GitHub >

github_iconTop Results From Across the Web

In Java, what is the difference between catch a generic ...
Currently I'm catching only generic exceptions, but i want change this to catch the specific exceptions, but what is the advantage of this?...
Read more >
Handle errors and exceptions in MSAL.NET
Learn how to handle errors and exceptions, Conditional Access claims challenges, and retries in MSAL.NET.
Read more >
What is a good approach to handling exceptions?
So I have several questions on the matter: Is catching generic exceptions that wrong an approach? Had a lot of cases (been burnt...
Read more >
9 Best Practices to Handle Exceptions in Java
Handling Java exceptions isn't easy, especially for beginners. Read this post to understand exceptions and best practices for using them.
Read more >
Best Practices for exceptions - .NET
Learn best practices for exceptions, such as using try/catch/finally, handling common conditions without exceptions, and using predefined .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found