Skip to content

Commit

Permalink
fix: error handling #56
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Jan 15, 2024
1 parent f1006ec commit e0eba03
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions R/routing.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ Routing <- R6::R6Class(
#' @details Initialise
#' @param path Prefix path.
initialize = function(path = "") {
self$error <- \(req, res) {
response_500()
}
private$.basepath <- path
private$.is_router <- path != ""
},
Expand Down Expand Up @@ -395,13 +392,21 @@ Routing <- R6::R6Class(
request$params <- set_params(request$PATH_INFO, private$.routes[[i]]$route)

# get response
response <- tryCatch(private$.routes[[i]]$fun(request, res),
response <- tryCatch(
private$.routes[[i]]$fun(request, res),
error = function(error){
warning(error)
private$.routes[[i]]$error(request, res)
error
}
)

if(inherits(response, "error") && !is.null(private$.routes[[i]]$error)){
return(private$.routes[[i]]$error(request, res))
}

if(inherits(response, "error") && !is.null(self$error)){
return(self$error(request, res))
}

if(promises::is.promising(response)){
return(
promises::then(
Expand Down

0 comments on commit e0eba03

Please sign in to comment.