{"size": 1467, "ext": "scrbl", "max_stars_repo_path": "request/private/exn.scrbl", "max_stars_repo_name": "yurkobb/racket-request", "max_stars_repo_stars_event_min_datetime": "2015-09-10T00:32:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-25T21:00:17.000Z", "max_issues_repo_path": "request/private/exn.scrbl", "max_issues_repo_name": "yurkobb/racket-request", "max_issues_repo_issues_event_min_datetime": "2015-07-20T19:57:43.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-30T06:21:09.000Z", "max_forks_repo_path": "request/private/exn.scrbl", "max_forks_repo_name": "yurkobb/racket-request", "max_forks_repo_forks_event_min_datetime": "2015-07-13T06:34:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-06-07T15:01:08.000Z"}
{"max_stars_count": 21, "max_issues_count": 19, "max_forks_count": 6, "avg_line_length": 36.675, "max_line_length": 73, "alphanum_fraction": 0.6946148603}
#lang scribble/manual

@(require "../doc-utils/examples.rkt"
          "../doc-utils/def.rkt"
          (for-label request
                     racket))

@title{HTTP Status Code Exception Throwing}

@defstruct*[(exn:fail:network:http:code exn:fail:network)
            ([code exact-positive-integer?])]{
  An exception structure type for non-success HTTP error codes.
  All codes in the range @racket[(<= 400 code 599)] are defined
  as error cases. This exception is thrown by @racket[http-requester]s
  wrapped by @racket[requester-http-exn].
}

@defproc[(requester-http-exn [requester requester?])
         requester?]{
  Given a @racket[requester] whose responses are @racket[http-response]s,
  returns a requester whose responses are the only the response bodies
  of @racket[requester]. In the event of failure error codes
  in the response, an @racket[exn:fail:network:http:code] exception
  is thrown which contains the code and response body.
}

@defrequester[http-requester/exn]{
  Like @racket[http-requester], but throws exceptions for failure codes
  and returns the http response body as it's response. Equivalent to
  @racket[(requester-http-exn http-requester)].
}

@defproc[(http-exn-of-code? [code exact-positive-integer?]
                            [v any/c])
         boolean?]{
  Returns @racket[#t] if @racket[v] is an instance of
  @racket[exn:fail:network:http:code] whose status code is
  @racket[code], and returns @racket[#f] otherwise.
}
