I want to add a filter in R plumber APi which can throwh an error of unresposive urls

685 views Asked by At

Need a filter which can show non responsive url with an error code

    #* Return LDA of all sites
    #* @param a Enter your Website
    #* @param b:[chr] Enter URLs
    #* @param v The focused keyword
    #* pr_set_error(pr, fun)
    function(req, res){
      if (req$b== FALSE){
        res$status <- 500 # Unauthorized
        return(list(error="Unresponsive URL"))
      } else {
        plumber::forward()
      }
    }
    #* @post  /LDA
    
    function(a,b,v) {

#calculation}

please help me!

1

There are 1 answers

0
Bruno Tremblay On

I'm wildly guessing here

#* Return LDA of all sites
#* @param a Enter your Website
#* @param b:[chr] Enter URLs
#* @param v The focused keyword
#* @post  /LDA
function(a,b,v) {
  #calculation
}

#* @filter unresponsive_url
function(req, res){
  if (any(req$args$b == FALSE)) {
    res$status <- 500 # Unauthorized
    return(list(error="Unresponsive URL"))
  } else {
    plumber::forward()
  }
}