API errors not returning in deployment but correctly returns in IDE

I have my API built using plumber. When I run it in R Workbench the error code returns with the correct message. But when the same API reployed in RConnect, doesn't return the message.

Error message when the app is run in Workbench during dev:

{
  "error": "500 - Internal server error",
  "message": "Error in value[[3L]](cond): nanodbc/nanodbc.cpp:1655: 00000: INSERT 1: The transition 13 > 13 is not allowed. Please contact System Admin.,  \n<SQL> 'EXEC\t[dbo].[sp_*******]\n"
}

Error message when the app is run in RConnect in Production:

{
  "error": "500 - Internal server error"
}

Repex showing my decorated function and how I am error catching:

#* @apiTitle My API 
#* @apiDescription This is a Repex
#* 
#* #* Run SP
#* @param myParam
#* @post /run_sp
function(myParam){
  
  # Trycatching the ruinning of the sp
  tryCatch(
    expr = 
      {
        result <- dbGetQuery(mydb, paste0("EXEC	[dbo].[my_sp] @myParam = ", myParam,))
        return(result)
      },
    error = function(e) {
      warning(e$message)
      stop(e$message)
    })
  
  dbDisconnect(mydb) 
}

#* @plumber
function(pr) {
  pr %>%
    # Overwrite the default serializer to return unboxed JSON
    pr_set_serializer(serializer_unboxed_json())
}

Debugging has to be activated to return more details during an internal state failure. The default value depends on interactive().

plumber::Plumber$new() |> plumber::pr_set_debug(TRUE)

That worked! Thanks a tonne :slight_smile:

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.