Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wanted to throw an exception using Reactive Spring only if username a new user wanted to have was being used for someone what was't him
private Mono<UserDto> validateUpdate(Long partyId, UserDto request) {
return partyClient.getIndividual(partyId)
.flatMap(r -> securityClient.getByUserName(request.getUsername()))
.switchIfEmpty(Mono.just(UserModel.builder().withId(partyId).build())) //dummy to have something to compare with and kee the reactive flow "flowing"
.flatMap(r -> {
if (!r.getId().equals(partyId)) {
throw new UserAlreadyExistsException("Username already taken");
}
return Mono.just(request);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.