Exception: X::InvalidResponse
- Defined in:
- x-core/lib/x/core/errors/invalid_response.rb
Overview
Error raised for a successful response whose body is not JSON, such as the page of a proxy or captive portal
It is an X::HTTPError, so that code that rescues the failures of a response reads it as it reads any other: the status is HTTPError#status, the headers are HTTPError#headers, the body is #body, and HTTPError#http_method and HTTPError#uri are the request it answered. A body that is not JSON describes no problem, so HTTPError#problem is nil and HTTPError#problems empty.
Instance Method Summary collapse
-
#body ⇒ String?
The body that is not JSON: the whole body of a response, or the line of a stream.
-
#initialize(message = nil, http_response: nil, status: nil, headers: nil, body: nil, http_method: nil, uri: nil) ⇒ InvalidResponse
constructor
Initialize a new InvalidResponse.
Constructor Details
#initialize(message = nil, http_response: nil, status: nil, headers: nil, body: nil, http_method: nil, uri: nil) ⇒ InvalidResponse
Initialize a new InvalidResponse
Public, so that code that rescues an InvalidResponse can be tested with one built from the status, headers, and body of a response, or from a Net::HTTP response, as ResponseParser and the stream of x-streaming build one. The error names the request, when given its method and URI, as x-core names the request the response answers.
It can be raised as any other exception is, as in raise X::InvalidResponse, and is built with a status of 200 when it is given neither a response nor a status, as HTTPError states.
56 57 58 59 |
# File 'x-core/lib/x/core/errors/invalid_response.rb', line 56 def initialize( = nil, http_response: nil, status: nil, headers: nil, body: nil, http_method: nil, uri: nil) @body = body super(, http_response:, status:, headers:, body: (body if http_response.nil?), http_method:, uri:) end |
Instance Method Details
#body ⇒ String?
The body that is not JSON: the whole body of a response, or the line of a stream
The body of a stream can be read only as it arrives, so an error raised for a line of a stream holds that line. It is tagged UTF-8, as Response#body is, and keeps the bytes of a body that is not valid UTF-8.
An error given no body holds the body of its response, as HTTPError#body does, once that response has been read whole. The body of a response that has not been read, as that of a stream still arriving, is never read for it, since reading it would wait for the rest of the stream, or take the lines the stream has yet to read.
29 |
# File 'x-core/lib/x/core/errors/invalid_response.rb', line 29 def body = @body || body_read |