Class: Airbrake::SyncSender Private
- Inherits:
-
Object
- Object
- Airbrake::SyncSender
- Includes:
- Loggable
- Defined in:
- lib/airbrake-ruby/sync_sender.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Responsible for sending data to Airbrake synchronously via PUT or POST methods. Supports proxies.
Constant Summary collapse
- CONTENT_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns body for HTTP requests.
'application/json'.freeze
- BACKLOGGABLE_STATUS_CODES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Returns response codes that are good to be backlogged.
[ Response::BAD_REQUEST, Response::FORBIDDEN, Response::ENHANCE_YOUR_CALM, Response::REQUEST_TIMEOUT, Response::CONFLICT, Response::TOO_MANY_REQUESTS, Response::INTERNAL_SERVER_ERROR, Response::BAD_GATEWAY, Response::GATEWAY_TIMEOUT, ].freeze
Instance Method Summary collapse
-
#close ⇒ void
private
Closes all the resources that this sender has allocated.
-
#initialize(method = :post) ⇒ SyncSender
constructor
private
A new instance of SyncSender.
-
#send(data, promise, endpoint = @config.error_endpoint) ⇒ Hash{String=>String}
private
Sends a POST or PUT request to the given
endpoint
with thedata
payload.
Methods included from Loggable
Constructor Details
#initialize(method = :post) ⇒ SyncSender
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of SyncSender.
29 30 31 32 33 34 |
# File 'lib/airbrake-ruby/sync_sender.rb', line 29 def initialize(method = :post) @config = Airbrake::Config.instance @method = method @rate_limit_reset = Time.now @backlog = Backlog.new(self) if @config.backlog end |
Instance Method Details
#close ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Closes all the resources that this sender has allocated.
68 69 70 |
# File 'lib/airbrake-ruby/sync_sender.rb', line 68 def close @backlog.close end |
#send(data, promise, endpoint = @config.error_endpoint) ⇒ Hash{String=>String}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sends a POST or PUT request to the given endpoint
with the data
payload.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/airbrake-ruby/sync_sender.rb', line 41 def send(data, promise, endpoint = @config.error_endpoint) return promise if rate_limited_ip?(promise) req = build_request(endpoint, data) return promise if missing_body?(req, promise) begin response = build_https(endpoint).request(req) rescue StandardError => ex reason = "#{LOG_LABEL} HTTP error: #{ex}" logger.error(reason) return promise.reject(reason) end parsed_resp = Response.parse(response) handle_rate_limit(parsed_resp) @backlog << [data, endpoint] if add_to_backlog?(parsed_resp) return promise.reject(parsed_resp['error']) if parsed_resp.key?('error') promise.resolve(parsed_resp) end |