Exception: Shift::Api::Core::Errors::ServerError

Inherits:
ApiError
  • Object
show all
Defined in:
lib/shift/api/core/errors.rb

Instance Attribute Summary

Attributes inherited from ApiError

#env, #original_exception

Instance Method Summary collapse

Methods inherited from ApiError

from_jsonapi_client, #initialize

Constructor Details

This class inherits a constructor from Shift::Api::Core::Errors::ApiError

Instance Method Details

#backtraceObject

Prepend API backtrace to the backtrace from the gem



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/shift/api/core/errors.rb', line 49

def backtrace
  original_backtrace = super
  return nil if original_backtrace.nil?

  api_errors = env.response.body["errors"]
  return original_backtrace if api_errors.nil?

  api_backtrace = api_errors[0].dig("meta", "backtrace")
  return original_backtrace if api_backtrace.nil?

  api_backtrace.map { |entry| "/<shift_api>#{entry}" }.concat(original_backtrace)
end

#messageObject

Replace message with more useful error from the API



38
39
40
41
42
43
44
45
46
# File 'lib/shift/api/core/errors.rb', line 38

def message
  default_message = "Internal Server Error\n#{env.response.body}"

  api_errors = env.response.body["errors"]
  return default_message if api_errors.nil?

  api_exception = api_errors[0].dig("meta", "exception")
  api_exception ? api_exception : default_message
end