Exception: BrainzLab::ServerError

Inherits:
Error
  • Object
show all
Defined in:
lib/brainzlab/errors.rb

Overview

Raised when a server-side error occurs.

Examples:

Server error

raise BrainzLab::ServerError.new(
  "Internal server error",
  hint: "This is a temporary issue. Please retry your request.",
  code: "internal_server_error"
)

Constant Summary

Constants inherited from Error

Error::DOCS_BASE_URL

Instance Attribute Summary collapse

Attributes inherited from Error

#code, #context, #docs_url, #hint

Instance Method Summary collapse

Methods inherited from Error

#as_json, #detailed_message, #inspect, #to_h, #to_s

Constructor Details

#initialize(message = nil, hint: nil, docs_url: nil, code: nil, context: nil, status_code: nil, request_id: nil) ⇒ ServerError

Returns a new instance of ServerError.



281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/brainzlab/errors.rb', line 281

def initialize(message = nil, hint: nil, docs_url: nil, code: nil, context: nil, status_code: nil, request_id: nil)
  @status_code = status_code
  @request_id = request_id

  hint ||= 'This is a temporary issue. Please retry your request. If the problem persists, contact support.'
  docs_url ||= "#{DOCS_BASE_URL}/sdk/ruby/troubleshooting#server-errors"
  code ||= 'server_error'

  context ||= {}
  context[:status_code] = status_code if status_code
  context[:request_id] = request_id if request_id

  super(message, hint: hint, docs_url: docs_url, code: code, context: context.empty? ? nil : context)
end

Instance Attribute Details

#request_idString? (readonly)

Returns Request ID for support reference.

Returns:

  • (String, nil)

    Request ID for support reference



279
280
281
# File 'lib/brainzlab/errors.rb', line 279

def request_id
  @request_id
end

#status_codeInteger? (readonly)

Returns HTTP status code from the server.

Returns:

  • (Integer, nil)

    HTTP status code from the server



276
277
278
# File 'lib/brainzlab/errors.rb', line 276

def status_code
  @status_code
end