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).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.



50
51
52
53
# File 'lib/fluent/plugin/bigquery/errors.rb', line 50

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



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

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.



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

def origin
  @origin
end

Class Method Details

.inherited(subclass) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/fluent/plugin/bigquery/errors.rb', line 39

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

.retryable_error?(google_api_error) ⇒ Boolean

Returns:

  • (Boolean)


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

def retryable_error?(google_api_error)
  e = google_api_error
  reason = e.respond_to?(:reason) ? e.reason : nil

  retryable_error_reason?(reason) ||
    (e.is_a?(Google::Apis::ServerError) && RETRYABLE_STATUS_CODE.include?(e.status_code))
end

.retryable_error_reason?(reason) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.retryable_insert_errors_reason?(reason) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/fluent/plugin/bigquery/errors.rb', line 33

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

.wrap(google_api_error, message = nil, force_unretryable: false) ⇒ Object



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

def wrap(google_api_error, message = nil, force_unretryable: false)
  e = google_api_error
  return UnRetryableError.new(message, e) if force_unretryable

  if retryable_error?(e)
    RetryableError.new(message, e)
  else
    UnRetryableError.new(message, e)
  end
end

Instance Method Details

#bodyObject



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

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

#reasonObject



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

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

#retryable?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/fluent/plugin/bigquery/errors.rb', line 75

def retryable?
  false
end

#status_codeObject



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

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