EasyLog - Retry on exception



If you need to retry a method on some specific exception or exceptions then you can use these parameters to setup the retry functionality.

Class<? extends Throwable>[] retryExceptions() default {} - a list of exceptions to retry on.

int retryAttempts() default 1 - retry retryAttempts times.

long retryDelay() default 0 - time delay between attempts in ms.

These parameters can be set for each method individually.

Example

@LogIt(retryExceptions = {ForbiddenException.class, BadRequestException.class}, 
	retryDelay = 1000, 
	retryAttempts = 3)

In the logs you will see

16:26:43.969 [main] ERROR io.lenar.easy.log.UneasyLogger - javax.ws.rs.BadRequestException: HTTP 400 Bad Request 
 <- UserService.findUser(..)
Retry 1/3 in 1000 ms
16:26:45.017 [main] ERROR io.lenar.easy.log.UneasyLogger - javax.ws.rs.BadRequestException: HTTP 400 Bad Request 
 <- UserService.findUser(..)
Retry 2/3 in 1000 ms
16:26:46.063 [main] ERROR io.lenar.easy.log.UneasyLogger - javax.ws.rs.BadRequestException: HTTP 400 Bad Request 
 <- UserService.findUser(..)
Retry 3/3 in 1000 ms
16:26:47.112 [main] ERROR io.lenar.easy.log.ExceptionLogger - javax.ws.rs.BadRequestException: HTTP 400 Bad Request
 <- UserService.findUser(..): 
{"code":400,"message":"First name is required","path":null,"parameterName":"firstName"}

Note: You can specify a parent exception to cover all child exceptions. For example WebApplicationException covers BadRequestException, ForbiddenException,NotFoundException etc