'Intercepting 401 error by MSAL during backend access
In my project we acquire a token via MSAL in the main java application and provide this token in lots of different calls to a library (aka backend client) that handles the actual backend communication. By default, that works fine - until that token is invalid and then a 401 exception gets thrown that the library is unable to handle itself and forwards it as an exception to the main application (401 message - giving up).
I'd like to avoid surrounding each of those library call with a try-catch to handle it resulting in tons of redundant code here (if 401, get new token and use that). I'm more looking for a general way to handle all exceptions and just look for that 401 to get a new token and resume that function. So more or less a try-catch above a whole class with lots of functions + resume option. Maybe, it's also possible to intercept MSAL? Does Java actually support something like that? Any recommendations?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
