Learn R Programming

plumber (version 1.2.2)

pr_set_error: Set the error handler that is invoked if any filter or endpoint generates an error

Description

Set the error handler that is invoked if any filter or endpoint generates an error

Usage

pr_set_error(pr, fun)

Value

The Plumber router with a modified error handler

Arguments

pr

A Plumber API. Note: The supplied Plumber API object will also be updated in place as well as returned by the function.

fun

An error handler function. This should accept req, res, and the error value

Examples

Run this code
if (FALSE) {
handler_error <- function(req, res, err){
  res$status <- 500
  list(error = "Custom Error Message")
}

pr() %>%
  pr_get("/error", function() log("a")) %>%
  pr_set_error(handler_error) %>%
  pr_run()
}

Run the code above in your browser using DataLab