mavericks: [Proposal] Global error handler for execute functions

I have the requirement to trace all errors in app, even if those are properly handled by the code and UI. So i need to create some global error handler for all execute function, that will be called on Fail reducer set. My proposal:

Add new property to MavericksViewModelConfig with signature something like:

val executeErrorHandler: ((Exception) -> Unit)? = null

I’m not sure that should be called handler, since it wouldn’t have any impact on error handling, it’s just for logging/tracing purposes. Maybe name executeErrorLogger would be more appropriate?

Next, i’d add the same field to MavericksViewModelConfigFactory that would be passed down to configs.

In MavericksViewModel i’d add call config.executeErrorHandler?.invoke(e) after setState { reducer(Fail(e ... for all execute functions.

What do you think about that? If it’s fine i’ll create a PR with that.

Also, i have a minor question about error handling - is there a particular reason to catch Exception instead of Throwable?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 22 (14 by maintainers)

Most upvoted comments

So maybe an interface like this:

interface AsyncEventsListener {
    fun onSuccess(event: Success<*>) {}
    fun onLoading(event: Loading<*>) {}
    fun onFail(event: Fail<*>) {}
}

Default method implementations might be handy if someone wants to listen only to one/two of events. I can go through the codebase and find all places that can emit Async events and invoke proper methods there.

I can replace Exception with Throwable in the same PR if that’s ok with you