Exception: Underpass::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/underpass/errors.rb

Overview

Base error class for all Underpass errors.

Provides structured error data parsed from Overpass API responses.

Examples:

begin
  features = Underpass::QL::Query.perform(bbox, query)
rescue Underpass::Error => e
  e.code           # => "timeout"
  e.error_message  # => "Query timed out..."
  e.details        # => { line: 3, timeout_seconds: 25 }
  e.http_status    # => 504
  e.to_h           # => { code: "timeout", message: "...", details: {...} }
end

Direct Known Subclasses

ApiError, RateLimitError, TimeoutError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, code: nil, error_message: nil, details: {}, http_status: nil) ⇒ Error

Creates a new error with optional structured data.

Parameters:

  • message (String, nil) (defaults to: nil)

    the error message (used by StandardError)

  • code (String, nil) (defaults to: nil)

    the error code

  • error_message (String, nil) (defaults to: nil)

    the detailed error message

  • details (Hash) (defaults to: {})

    additional error details

  • http_status (Integer, nil) (defaults to: nil)

    the HTTP status code



40
41
42
43
44
45
46
# File 'lib/underpass/errors.rb', line 40

def initialize(message = nil, code: nil, error_message: nil, details: {}, http_status: nil)
  @code = code
  @error_message = error_message || message
  @details = details || {}
  @http_status = http_status
  super(@error_message || message)
end

Instance Attribute Details

#codeString? (readonly)

Returns the error code (e.g., “timeout”, “memory”, “syntax”).

Returns:

  • (String, nil)

    the error code (e.g., “timeout”, “memory”, “syntax”)



22
23
24
# File 'lib/underpass/errors.rb', line 22

def code
  @code
end

#detailsHash (readonly)

Returns additional error details (varies by error type).

Returns:

  • (Hash)

    additional error details (varies by error type)



28
29
30
# File 'lib/underpass/errors.rb', line 28

def details
  @details
end

#error_messageString? (readonly)

Returns the human-readable error message.

Returns:

  • (String, nil)

    the human-readable error message



25
26
27
# File 'lib/underpass/errors.rb', line 25

def error_message
  @error_message
end

#http_statusInteger? (readonly)

Returns the HTTP status code from the API response.

Returns:

  • (Integer, nil)

    the HTTP status code from the API response



31
32
33
# File 'lib/underpass/errors.rb', line 31

def http_status
  @http_status
end

Instance Method Details

#to_hHash

Returns a hash representation of the error.

Returns:

  • (Hash)

    the error as a hash with :code, :message, and :details keys



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

def to_h
  {
    code: code,
    message: error_message,
    details: details
  }
end

#to_jsonString

Returns a JSON representation of the error.

Parameters:

  • args (Array)

    arguments passed to JSON.generate

Returns:

  • (String)

    the error as a JSON string



63
64
65
# File 'lib/underpass/errors.rb', line 63

def to_json(*)
  to_h.to_json(*)
end