Skip to content
Advertisement

Reactive – Improve Mono syntax

I have this block of code that works fine:

JavaScript

To summarize it:

  • calls the isBlacklistedToken function (returns a Mono<Boolean> with the result of the refresh token)
  • If the refresh token is blacklisted, throws an UnauthorizedException
  • If the refresh token is not blacklisted, does the same process for the access token
  • If both tokens are not blacklisted, finally blacklists them.

This syntax, while it works, seems a bit sloppy. Is there a way to improve that? I wrote this piece of code, and while it throws an exception, the last part (blacklisting the tokens) always executes – peraphs my knowledge of reactive programming is a bit off.

JavaScript

Edit: adding the isBlacklistedToken method

JavaScript

and the respective blacklistService call (just a repository call, really simple)

JavaScript

Advertisement

Answer

I would suggest the following:

JavaScript

Sorry if there is some compile error but I tried this in Kotlin and needed to translate it to Java, which is become less and less easy.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement