abort_internal_error inside @async

Đang mở
#85 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
r
Lĩnh vực
api, backend-api-design

Hướng nghiên cứu

Start by reproducing the interaction between abort_internal_error() and @async, then inspect how errors propagate out of mirai and how @then handlers are selected. Done means an endpoint using both features propagates the intended error and status without requiring the tryCatch workaround shown in the issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
R
Star
119
Fork
17
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của posit-dev/plumber2

Tất cả issue của posit-dev/plumber2

Issue tương tự

Thêm issue về R

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.