Skip to content

Handle Errors and Exceptions

Ray Luo edited this page Oct 29, 2019 · 2 revisions

Errors and Exceptions in MSAL Python

Most errors are conveyed as a return value

In MSAL Python, if an acquire token API call was unsuccessful, app developer is expected to handle such runtime error on the spot. So most errors are simply surfaced as the return value of each API call. That return value, as described in MSAL Python API Reference Doc, is a dictionary representing the json response from Microsoft Identity Platform:

  • A successful response would contain "access_token" key, among others.
  • An error response would contain "error" and usually "error_description", among others.

The format of these response is well defined in the industry standard OAuth2 protocol. In particular, when an error is returned, its error_description would contain a human-readable message, which in turn typically contains an Microsoft Identity Platform error code that is documented here.

Exceptions are for something unexpected

MSAL Python would also raise ValueError exception when/if some input parameter(s) are malformed. Consider them as "compiling error" in static languages, that you would have to fix otherwise your app won't be able to run anyway. Other than that, MSAL Python might raise or relay some RuntimeError exceptions, but your app does not have to catch and handle them.

Clone this wiki locally