New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to have custom 405 handler #759
Conversation
Co-authored-by: Barret Schloerke <barret@rstudio.com>
#' pr$set405Handler(function(req, res) {cat(req$PATH_INFO)}) | ||
#' } | ||
set405Handler = function(fun){ | ||
private$unallowedMethodHandler <- fun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set404Handler
should maybe do the same (to avoid errors that aren't caught until runtime)?
private$unallowedMethodHandler <- fun | |
stopifnot(is.function(fun)) | |
args <- names(formals(fun)) | |
if (!all(c("req", "res") %in% args)) { | |
stop("fun must have formal arguments for req and res") | |
} | |
private$unallowedMethodHandler <- fun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple other plumber functions that take a function as input and are executed at runtime with potential failure. This might be material for another PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@meztez Would you like / have time to do a PR for the other method parameter checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually, I still have the regular job thing to do 😄
Scrath this PR, I'm thinking long term we should have a better way to handler errors. Something like serializers and parsers, a collection of error handler. This PR is more a bandaid than a real solution. |
Fixes #757
I could not explain it better than #757
This is crude, I would still prefer to have a more global approach to custom error handling
PR task list:
devtools::document()