Description Usage Arguments Value Note Examples
View source: R/utils-middleware.R
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.
1 | handleErrors(beakr = NULL, FUN = jsonError)
|
beakr |
Beakr instance |
FUN |
a function to handle the error response |
A Beakr
instance with added middleware.
If you run the example in the console, be sure to
stopServer(bekar)
when you are done.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.