This default error handler should be added at the end of the beakr pipeline, right before listen(). Errors generated by any previous step will be returned within a JSON wrapper.

handleErrors(beakr = NULL, FUN = jsonError)

Arguments

beakr

Beakr instance

FUN

a function to handle the error response

Value

A Beakr instance with added middleware.

Note

If you run the example in the console, be sure to stopServer(bekar) when you are done.

Examples

# \donttest{ library(beakr) # Create an new beakr instance beakr <- newBeakr() # beakr pipeline beakr %>% # Respond to GET requests at the "/hi" route httpGET(path = "/hi", function(req, res, err) { print("Hello, World!") }) %>% # Respond to GET requests at the "/bye" route httpGET(path = "/bye", function(req, res, err) { print("Farewell, my friends.") }) %>% handleErrors() %>% # Start the server on port 25118 listen(host = "127.0.0.1", port = 25118, daemon = TRUE) # ------------------------------------------------------------ # POINT YOUR BROWSER AT: # * http://127.0.0.1:25118/NOT_A_ROUTE # # THEN, STOP THE SERVER WITH stopServer(beakr) # ------------------------------------------------------------ # Stop the beakr instance server stopServer(beakr) # }