http_problem: Describe a Problem with an HTTP Request

Description Usage Arguments Value See Also Examples

View source: R/package.R

Description

http_problem() creates the "Problem Details" structure defined in RFC 7807, used for reporting errors from HTTP APIs in a standard way.

There are also helper methods for the most common HTTP problems: HTTP 400 Bad Request, 404 Not Found, 401 Unauthorized, 403 Forbidden, 409 Conflict, and 500 Internal Server Error.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
http_problem(
  detail = NULL,
  status = 500L,
  type = NULL,
  title = NULL,
  instance = NULL,
  ...
)

bad_request(detail = NULL, instance = NULL, ...)

unauthorized(detail = NULL, instance = NULL, ...)

forbidden(detail = NULL, instance = NULL, ...)

not_found(detail = NULL, instance = NULL, ...)

conflict(detail = NULL, instance = NULL, ...)

internal_server_error(detail = NULL, instance = NULL, ...)

Arguments

detail

A human-readable string giving more detail about the error, if possible.

status

The HTTP status code appropriate for the response.

type

A URL pointing to human-readable documentation for this type of problem. When NULL, the type is generated based on the status code; see http_problem_types() for a list of the defaults.

title

A "short, human-readable summary of the problem type". When NULL, the title is generated based on the status code; see http_problem_types() for a list of the defaults.

instance

A URL that identifies the specific occurrence of the problem, if possible. When NULL this field is simply excluded.

...

Additional fields added to the problem as Extension Members.

Value

An object of class "http_problem", which has fields corresponding to an RFC 7807 Problem Details structure.

See Also

stop_for_http_problem for issuing R errors with these structures.

Examples

1
2
body <- bad_request("Parameter 'id' must be a number.")
str(body)

httpproblems documentation built on June 16, 2021, 5:08 p.m.