Tired of throwing exceptions or returning nonsense? Well, Resulter will save you!
Resulter provides simple to use Results. Why? Well, there are few benefits.
- Fewer exceptions or returning nonsense messages.
- Clear understanding of what went wrong with message() and error() methods.
- gRPC implementation.
- Project Reactor support.
The dependency for Resulter is available on Maven Central.
- Gradle
implementation 'com.iamceph.resulter:resulter-core:1.1.6'
implementation("com.iamceph.resulter", "resulter-core", "1.1.6")
implementation("com.iamceph.resulter", "kotlin-extensions", "1.1.6")
- Maven
<dependency>
<groupId>com.iamceph.resulter</groupId>
<artifactId>resulter-core</artifactId>
<version>1.1.6</version>
</dependency>
//this operation ended normally
public class Test {
public Resultable doSomething() {
Resultable okResult = Resultable.ok();
//this operation failed because it cannot find given user.
Resultable failedResult = Resultable.fail("Cannot find user!");
}
}
public class UserService {
public Resultable isAccessAllowed(Integer userId) {
if (userId == 1) {
return Resultable.ok();
}
return Resultable.fail("User is not allowed to access.");
}
public DataResultable<User> anotherCheck(Integer userId) {
//let's get if the user can enter
final Resultable result = isAccessAllowed(userId);
if (result.isFail()) {
return result.transform();
}
//this will fail if the user does not exist in the repo, neat, right? :)
return DataResultable.failIfNull(userRepository.findUser(userId));
}
}