Exception: Fluent::BigQuery::Error Abstract

Inherits:
StandardError
  • Object
show all
Defined in:
lib/fluent/plugin/bigquery/errors.rb

Overview

This class is abstract.

Direct Known Subclasses

RetryableError, UnRetryableError

Constant Summary collapse

RETRYABLE_ERROR_REASON =
%w(backendError internalError rateLimitExceeded tableUnavailable).freeze
RETRYABLE_INSERT_ERRORS_REASON =
%w(timeout backendError internalError rateLimitExceeded).freeze
RETRYABLE_STATUS_CODE =
[500, 502, 503, 504]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, origin = nil) ⇒ Error

Returns a new instance of Error.



46
47
48
49
# File 'lib/fluent/plugin/bigquery/errors.rb', line 46

def initialize(message, origin = nil)
  @origin = origin
  super(message || origin.message)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/fluent/plugin/bigquery/errors.rb', line 51

def method_missing(name, *args)
  if @origin
    @origin.send(name, *args)
  else
    super
  end
end

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



44
45
46
# File 'lib/fluent/plugin/bigquery/errors.rb', line 44

def origin
  @origin
end

Class Method Details

.inherited(subclass) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/fluent/plugin/bigquery/errors.rb', line 35

def inherited(subclass)
  subclass.class_eval do
    class << self
      public :new
    end
  end
end

.retryable_error?(e) ⇒ Boolean

Parameters:

  • e (Google::Apis::Error)

Returns:

  • (Boolean)


21
22
23
# File 'lib/fluent/plugin/bigquery/errors.rb', line 21

def retryable_error?(e)
  e.is_a?(Google::Apis::ServerError) && RETRYABLE_STATUS_CODE.include?(e.status_code)
end

.retryable_error_reason?(reason) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/fluent/plugin/bigquery/errors.rb', line 25

def retryable_error_reason?(reason)
  RETRYABLE_ERROR_REASON.include?(reason)
end

.retryable_insert_errors_reason?(reason) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fluent/plugin/bigquery/errors.rb', line 29

def retryable_insert_errors_reason?(reason)
  RETRYABLE_INSERT_ERRORS_REASON.include?(reason)
end

.wrap(e, message = nil) ⇒ Object

Parameters:

  • e (Google::Apis::Error)
  • message (String) (defaults to: nil)


12
13
14
15
16
17
18
# File 'lib/fluent/plugin/bigquery/errors.rb', line 12

def wrap(e, message = nil)
  if retryable_error?(e)
    RetryableError.new(message, e)
  else
    UnRetryableError.new(message, e)
  end
end

Instance Method Details

#bodyObject



67
68
69
# File 'lib/fluent/plugin/bigquery/errors.rb', line 67

def body
  @origin && @origin.respond_to?(:body) ? @origin.body : nil
end

#reasonObject



59
60
61
# File 'lib/fluent/plugin/bigquery/errors.rb', line 59

def reason
  @origin && @origin.respond_to?(:reason) ? @origin.reason : nil
end

#retryable?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/fluent/plugin/bigquery/errors.rb', line 71

def retryable?
  false
end

#status_codeObject



63
64
65
# File 'lib/fluent/plugin/bigquery/errors.rb', line 63

def status_code
  @origin && @origin.respond_to?(:status_code) ? @origin.status_code : nil
end