AzureAD / microsoft-authentication-library-for-js

Microsoft Authentication Library (MSAL) for JS

Home Page:http://aka.ms/aadv2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve exception messages for loadExternalTokens

victor-pogor opened this issue · comments

Core Library

MSAL.js (@azure/msal-browser)

Wrapper Library

Not Applicable

Public or Confidential Client?

Public

Description

Hello, dear community,

I discovered that some error messages in this library are too generic and do not provide enough details on the type of error that occurred.

For example, the loadExternalTokens() method has at least 3 checks that could throw the same BrowserAuthErrorCodes.unableToLoadToken code (1, 2, 3).

This method calls other methods like loadIdToken() that also throw the same code.

Since the code (and the mapped message) is the same in all exceptional cases, it is really hard to troubleshoot what went wrong, we can see only one exception: Error loading token to cache.

Looking into git blame, I noticed the messages were more explicit and descriptive before this change.

I suggest two solutions here:

  1. Add separate BrowserAuthErrorCodes (and messages) for each type of exception
    For example BrowserAuthErrorCodes.noClientInfoInResponseOrOptions
  2. Keep the same BrowserAuthErrorCodes.unableToLoadToken but use logger to provide more info on what went wrong
    For example this.logger.error("TokenCache - Please provide clientInfo in the response or options.")

I would like to hear your feedback 😄

Thanks,
Victor.

Source

External (Customer)

Hi @tnorling, is this issue closed?

Cause I see the PR has other changes related to loadExternalTokens, not the exception message improvements.

@victor-pogor The linked PR does address your feedback amongst other changes. It removed most of the error scenarios outright, leaving only 2 error cases - one was changed to a more descriptive "non_browser_environment" error and the other now includes a log message describing why it threw. This change will be included in the next release.