Skip to content

abort_internal_error inside @async #85

Open

Description

@r2evans

I like both features: abort_internal_error() provides a more human readable error message and return status, and @async can be dead-simple. However, using both does not work due to how errors propagate out of mirai (a known property).

A workaround is to wrap most/all of the async'd endpoint in tryCatch, and return a non-error with enough details, and @then abort with the error message. For example, incomplete code:

#* @get /something
#* async
function() {
  tryCatch({
    stop("my error")
    list(good = TRUE, res = mtcars[1:3,])
  }, error = function(err) {
    list(good = FALSE, err = conditionMessage(err))
  })
}
#* @then
function(response) {
  if (!response$body$good) {
    plumber2::abort_internal_error(response$body$err)
  }
  response$body$res
}

I think if an error is to be propagated, then any @then (if defined) would be overridden with a method that propagates the error as intended. Thoughts?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions