You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Response cannot be returned because it's being parsed to character #92
According to the documentation, the response object can be returned:
But when I try to run this minimal plumber app:
library(plumber2)
#* @plumberfunction(api) {
api|>
api_logger(
logger_console(),
access_log_format=plumber2::combined_log_format
) |>
api_get("/", function(request, response) {
response$status<-302Lresponse$set_header("Location", "echo/hello123")
})
}
#* Echo the parameter that was sent in#*#* @get /echo/<msg>#*#* @param msg:string The message to echo back.#*#* @response 200:{msg:string} A string containing the input message#*function(msg) {
msg
}
I get "internal server errors" instead of the redirect to echo/hello123 and can see in the logs the following errors messages:
2026-07-07 13:59:04.411662 - error: Error formatting the response body
2026-07-07 13:59:04.411662 - error: Caused by error in `as.character()`:
2026-07-07 13:59:04.411662 - error: ! cannot coerce type 'closure' to vector of type 'character'
This happens because response$set_header() returns the modified response object instead of NULL. So if I were first set the header and then the status, then everything works as expected (because the assignment returns NULL):
I tried to investigate if this is due to modification of set_header() that returning a response object erros but this code still causes the same error:
Activity