vlingo / xoom-common

The VLINGO XOOM platform SDK common tools shared across various projects.
Other
16 stars 10 forks source link

BasicCompletes Must Handle Latent Registration of recoverFrom(Exception) #12

Closed VaughnVernon closed 4 years ago

VaughnVernon commented 5 years ago

When there is an exception thrown prior to the receiverFrom(Exception) being registered on BasicCompletes<T> the outcome should be delayed until the registration is completed. If there is never a registration of receiverFrom(Exception) then the outcome will be unknown.

VaughnVernon commented 5 years ago

@Framstag Should be fixed. Please test and confirm.

Framstag commented 5 years ago

Updates to current master via bintray...

Modified example as follows:

private fun getUser(id: String): Completes<Response> {
        val userId = UserId.from(id)
        logger.info("Loading user $userId...")
        return stage.maybeActorOf(IUser::class.java,addressFactory.from(userId.toString()))
            .andThen {
                maybeUser ->
                logger.info("Return Response.Status.Ok")
                if (maybeUser.isEmpty) {
                    throw Exception("Not found")
                }
                Response.of(Response.Status.Ok, serialized(maybeUser.orElse(null)))
            }
            .recoverFrom {
                    e ->
                logger.error("Error:",e)
                logger.warn("Return Response.Status.NotFound: " + e.message)
                Response.of(Response.Status.NotFound) // Response
            }
    }

Exception is caught and printed as expected. Analysed code in debugger. Exception is stored during andThen() and later on handled during recoverFrom() call.

Rest call though does not return (curl is hanging).