Plumber Error Messages and Postman

Dear Community,
I would like to know how to set up a nice error message that can provide to the user if some parameters are missing.

I hope one day this feature could be added automatically from plumber

I am using this code when error happens

#* @tag ErrorMessages
#* @param vegetationindex:character 
#* @param filterTime:character 
#* @param initialmap:character 
#* @post /value
#* @serializer octet
function(res, req, vegetationindex, filterTime, initialmap) {
  
  future::future({
    
    check_can_use<-req$module_activation$SatelliteImages==TRUE
    
    if (check_can_use==TRUE) {
      
     maps_to_check<-c("CartoNormal","CartoDark","OpenStreetMap","EsriWorldImagery","OpenTopoMap")
      
      if (initialmap %in% maps_to_check) {
      } else {
        res$status <- 400  
        list(Error = "You requested a initial map that is not in the available list of base maps. Please use only those available in the list CartoNormal; CartoDark, OpenStreetMap, EsriWorldImagery, OpenTopoMap")
      }
    } else {
      res$status <- 400  
      list(Error = "Invalid credentials")
      
    }
  })
}

This is the log of the plumber api

While when i am using the postman this is the results

I have found a nice solution by using the follow code

    res$status <- 400
    res$body <- jsonlite::toJSON(auto_unbox = TRUE, list(
      status = 400,
      message = "You are not allowed to use this endpoint"
    ))
    print(res)
    return(res)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.