Update. We've got a work around. The problem goes ...
# micronaut
m
Update. We've got a work around. The problem goes away if we don't use
Exception
, but instead use a custom class (e.g. ApiException) in the handler, and then add an
.onErrorResumeNext{}
to bubble the exception:
Copy code
@Produces
@Singleton
@Requires(classes = [ApiException::class])
class ApiExceptionHandler : ExceptionHandler<ApiException, HttpResponse<Any>> {
    override fun handle(request: HttpRequest<Any>, exception: ApiException): HttpResponse<Any> {
        println("ApiExceptionHandler handle called")
        return HttpResponse.serverError(0)
    }
}

class ApiException(message: String? = null, cause: Throwable) : Exception(message, cause) {
    constructor(cause: Throwable) : this(null, cause)
}


    // ... in controller:
    override fun createMaybeObjects(count: Int): Maybe<List<Data>> {
        return Maybe.fromCallable { repo.createList(count) }
                .onErrorResumeNext { t: Throwable ->
                    Maybe.error(ApiException(t))
                }
    }
which appears to be rock solid. Interestingly, there's still a 50/50 issue if I use
Maybe.error(Exception(t))
and don't use a custom exception anywhere.