HTTPError: Helps to generate HTTP error responses

Description Usage Format Functions Public fields Methods See Also Examples

Description

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".

Class to generate HTTP error responses.

Usage

1

Format

An object of class HTTPError (inherits from R6) of length 39.

Functions

Public fields

content_type

Type of the error response.

encode

Function to encode response body.

Methods

Public methods


Method new()

Creates HTTPError object.

Usage
HTTPErrorFactory$new(content_type = "text/plain", encode = as.character)
Arguments
content_type

Type of the error response.

encode

Function to encode response body.


Method set_content_type()

Set content type of response.

Usage
HTTPErrorFactory$set_content_type(content_type)
Arguments
content_type

Type of the error response.

Details

Modifying HTTPError 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 HTTPErrorFactory$set_content_type() will impact not only user code, but also the errors format produced by RestRserve. Same holds for HTTPErrorFactory$set_encode() method below.


Method set_encode()

Set encode for the given content type.

Usage
HTTPErrorFactory$set_encode(encode)
Arguments
encode

Function to encode response body.


Method reset()

Resets HTTPError to the default RestRserve state.

Usage
HTTPErrorFactory$reset()

Method error()

Generate HTTP error response with a given status code and body.

Usage
HTTPErrorFactory$error(status_code, body = NULL, ...)
Arguments
status_code

HTTP status code.

body

Response body.

...

Additional named arguments which will be passed to Response$new(). headers may be particularly useful.

Returns

Response object.


Method bad_request()

Generates corresponding http error.

Usage
HTTPErrorFactory$bad_request(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method unauthorized()

Generates corresponding http error.

Usage
HTTPErrorFactory$unauthorized(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method forbidden()

Generates corresponding http error.

Usage
HTTPErrorFactory$forbidden(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method not_found()

Generates corresponding http error.

Usage
HTTPErrorFactory$not_found(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method method_not_allowed()

Generates corresponding http error.

Usage
HTTPErrorFactory$method_not_allowed(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method not_acceptable()

Generates corresponding http error.

Usage
HTTPErrorFactory$not_acceptable(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method conflict()

Generates corresponding http error.

Usage
HTTPErrorFactory$conflict(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method gone()

Generates corresponding http error.

Usage
HTTPErrorFactory$gone(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method length_required()

Generates corresponding http error.

Usage
HTTPErrorFactory$length_required(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method precondition_failed()

Generates corresponding http error.

Usage
HTTPErrorFactory$precondition_failed(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method payload_too_large()

Generates corresponding http error.

Usage
HTTPErrorFactory$payload_too_large(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method uri_too_long()

Generates corresponding http error.

Usage
HTTPErrorFactory$uri_too_long(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method unsupported_media_type()

Generates corresponding http error.

Usage
HTTPErrorFactory$unsupported_media_type(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method range_not_satisfiable()

Generates corresponding http error.

Usage
HTTPErrorFactory$range_not_satisfiable(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method unprocessable_entity()

Generates corresponding http error.

Usage
HTTPErrorFactory$unprocessable_entity(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method locked()

Generates corresponding http error.

Usage
HTTPErrorFactory$locked(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method failed_dependency()

Generates corresponding http error.

Usage
HTTPErrorFactory$failed_dependency(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method precondition_required()

Generates corresponding http error.

Usage
HTTPErrorFactory$precondition_required(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method too_many_requests()

Generates corresponding http error.

Usage
HTTPErrorFactory$too_many_requests(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method request_header_fields_too_large()

Generates corresponding http error.

Usage
HTTPErrorFactory$request_header_fields_too_large(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method unavailable_for_legal_reasons()

Generates corresponding http error.

Usage
HTTPErrorFactory$unavailable_for_legal_reasons(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method internal_server_error()

Generates corresponding http error.

Usage
HTTPErrorFactory$internal_server_error(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method not_implemented()

Generates corresponding http error.

Usage
HTTPErrorFactory$not_implemented(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method bad_gateway()

Generates corresponding http error.

Usage
HTTPErrorFactory$bad_gateway(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method service_unavailable()

Generates corresponding http error.

Usage
HTTPErrorFactory$service_unavailable(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method gateway_timeout()

Generates corresponding http error.

Usage
HTTPErrorFactory$gateway_timeout(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method version_not_supported()

Generates corresponding http error.

Usage
HTTPErrorFactory$version_not_supported(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method insufficient_storage()

Generates corresponding http error.

Usage
HTTPErrorFactory$insufficient_storage(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method loop_detected()

Generates corresponding http error.

Usage
HTTPErrorFactory$loop_detected(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method network_authentication_required()

Generates corresponding http error.

Usage
HTTPErrorFactory$network_authentication_required(...)
Arguments
...

Additional named arguments which will be passed to Response$new().

Returns

Response object.


Method clone()

The objects of this class are cloneable with this method.

Usage
HTTPErrorFactory$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

raise Application

Examples

1
2
3
4
5
6
check_list = function(x) {
  if (!is.list(x)) raise(HTTPError$bad_request())
  invisible(TRUE)
}
check_list(list())
try(check_list(1), silent = TRUE)

RestRserve documentation built on Jan. 13, 2021, 7:05 p.m.