Exception: SemanticLogger::Appender::Http::ResponseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/semantic_logger/appender/http.rb

Overview

Raised when the server answers a request with a status other than 2xx. Its message holds the status code, the redacted url, and the start of the response body, for the internal logger.

Constant Summary collapse

RETRY_LATER_CODES =

The statuses that ask the client to send the request again later, after which the server has not stored it: 408 Request Timeout, 429 Too Many Requests, and 503 Service Unavailable. Not a 500, which often comes again for the same request, or a 502 Bad Gateway or 504 Gateway Timeout, which a proxy can answer once the server behind it has stored it.

[408, 429, 503].freeze
CONTENT_CODES =

The 4xx statuses that reject the request for the entries it holds: 400 Bad Request, 413 Content Too Large, and 422 Unprocessable Content. A server can answer 400 for its own configuration too, such as Splunk's HTTP Event Collector for an index it does not know, which then rejects every part of a batch split up to find the entries at fault. A subclass that can tell such an answer from its body says so from #fails_any_batch?, as Appender::SplunkHttp does.

[400, 413, 422].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code:, body: nil) ⇒ ResponseError

Returns a new instance of ResponseError.



77
78
79
80
81
# File 'lib/semantic_logger/appender/http.rb', line 77

def initialize(message, code:, body: nil)
  super(message)
  @code = code
  @body = body
end

Instance Attribute Details

#body ⇒ Object (readonly)

Returns [String|nil] the body of the response, for a subclass that reads the server's own reason from it, such as Appender::SplunkHttp. Not in the message beyond its start, see MAX_LOGGED_RESPONSE_BODY.



75
76
77
# File 'lib/semantic_logger/appender/http.rb', line 75

def body
  @body
end

#code ⇒ Object (readonly)

Returns [Integer] the status code of the response.



70
71
72
# File 'lib/semantic_logger/appender/http.rb', line 70

def code
  @code
end

Instance Method Details

#content_rejected? ⇒ Boolean

Whether the server rejected the request for the entries it holds (see CONTENT_CODES), so that it may accept a part of them. It rejects a request with any other 4xx (see #rejected?), such as 401 Unauthorized, 403 Forbidden, or 404 Not Found, whatever it holds.

Returns:

  • (Boolean)


96
97
98
# File 'lib/semantic_logger/appender/http.rb', line 96

def content_rejected?
  CONTENT_CODES.include?(code)
end

#rejected? ⇒ Boolean

Whether the server rejected the request itself, with a 4xx status other than 408 and 429, so that sending it again cannot succeed. A 408, 429, or 5xx, and a 3xx, which asks to send it elsewhere, are problems with the destination instead.

Returns:

  • (Boolean)


86
87
88
# File 'lib/semantic_logger/appender/http.rb', line 86

def rejected?
  (400..499).cover?(code) && !retry_later?
end

#retry_later? ⇒ Boolean

Whether the server asks to send the request again later (see RETRY_LATER_CODES).

Returns:

  • (Boolean)


91
# File 'lib/semantic_logger/appender/http.rb', line 91

def retry_later? = RETRY_LATER_CODES.include?(code)