Global Object which holds functions to raise common http error responses.
Most of the time this class is used jointly with raise.
For example calling
raise(HTTPError$bad_request(body = "request is invalid"))
from any place in the user code will
interrupt request processing and return response with status code = 404 and body = "request is invalid".
R6::R6Class object.
content_type
:: character(1)
Type of the error response.
encode
:: function
Function to encode response body.
set_content_type
(content_type)
character(1)
-> self
Set content type of response.
NOTE that modifying HTTPError (for example with HTTPError$set_content_type("application/json")
)
will have global impact on RestRserve functionality.
By default HTTPError
is used by Application in order to produce http errors (404, 500, etc).
Hence changing HTTPError
with $set_content_type()
will impact not only user code,
but also the errors format produced by RestRserve. Same holds for $set_encode()
method below.
set_encode
(encode)
function
-> self
Set encode for the given content type.
error
(status_code, body, ...)
integer(1)
, raw()
| character()
, ...
-> Response
...
- additional named arguments which will be passed to Response$new(...)
.
headers
may be particularly useful.
Generate HTTP error response with a given status code and body
reset
()
-> self
Resets HTTPError
to the default RestRserve state.
bad_request
(...)
...
-> [Response]
Generates corresponding http error.
unauthorized
(...)
...
-> [Response]
Generates corresponding http error.
forbidden
(...)
...
-> [Response]
Generates corresponding http error.
not_found
(...)
...
-> [Response]
Generates corresponding http error.
method_not_allowed
(...)
...
-> [Response]
Generates corresponding http error.
not_acceptable
(...)
...
-> [Response]
Generates corresponding http error.
conflict
(...)
...
-> [Response]
Generates corresponding http error.
gone
(...)
...
-> [Response]
Generates corresponding http error.
length_required
(...)
...
-> [Response]
Generates corresponding http error.
precondition_failed
(...)
...
-> [Response]
Generates corresponding http error.
payload_too_large
(...)
...
-> [Response]
Generates corresponding http error.
uri_too_long
(...)
...
-> [Response]
Generates corresponding http error.
unsupported_media_type
(...)
...
-> [Response]
Generates corresponding http error.
range_not_satisfiable
(...)
...
-> [Response]
Generates corresponding http error.
unprocessable_entity
(...)
...
-> [Response]
Generates corresponding http error.
locked
(...)
...
-> [Response]
Generates corresponding http error.
failed_dependency
(...)
...
-> [Response]
Generates corresponding http error.
precondition_required
(...)
...
-> [Response]
Generates corresponding http error.
too_many_requests
(...)
...
-> [Response]
Generates corresponding http error.
request_header_fields_too_large
(...)
...
-> [Response]
Generates corresponding http error.
unavailable_for_legal_reasons
(...)
...
-> [Response]
Generates corresponding http error.
internal_server_error
(...)
...
-> [Response]
Generates corresponding http error.
not_implemented
(...)
...
-> [Response]
Generates corresponding http error.
bad_gateway
(...)
...
-> [Response]
Generates corresponding http error.
service_unavailable
(...)
...
-> [Response]
Generates corresponding http error.
gateway_timeout
(...)
...
-> [Response]
Generates corresponding http error.
version_not_supported
(...)
...
-> [Response]
Generates corresponding http error.
insufficient_storage
(...)
...
-> [Response]
Generates corresponding http error.
loop_detected
(...)
...
-> [Response]
Generates corresponding http error.
network_authentication_required
(...)
...
-> [Response]
Generates corresponding http error.
# NOT RUN {
check_list = function(x) {
if (!is.list(x)) raise(HTTPError$bad_request())
invisible(TRUE)
}
check_list(list())
try(check_list(1), silent = TRUE)
# }
Run the code above in your browser using DataLab