Class: NextStation::Result::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/next_station/result.rb

Overview

Structured error information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, message: nil, help_url: nil, details: {}, msg_keys: {}) ⇒ Error

Returns a new instance of Error.

Parameters:

  • type (Symbol)
  • message (String, nil) (defaults to: nil)
  • help_url (String, nil) (defaults to: nil)
  • details (Hash) (defaults to: {})
  • msg_keys (Hash) (defaults to: {})


115
116
117
118
119
120
121
# File 'lib/next_station/result.rb', line 115

def initialize(type:, message: nil, help_url: nil, details: {}, msg_keys: {})
  @type = type
  @message = message
  @help_url = help_url
  @details = details
  @msg_keys = msg_keys
end

Instance Attribute Details

#detailsHash (readonly)

Additional error details.

Examples:

{ age: [“must be greater than 18”] }

{ existing_email: true }

Returns:

  • (Hash)


106
107
108
# File 'lib/next_station/result.rb', line 106

def details
  @details
end

#help_urlString? (readonly)

An optional URL to help the end user resolve the error.

Returns:

  • (String, nil)


100
101
102
# File 'lib/next_station/result.rb', line 100

def help_url
  @help_url
end

#messageString? (readonly)

A human-readable message describing the error.

Examples:

“Email is already taken”

“User not found”

“Something went wrong, please try again.”

Returns:

  • (String, nil)


95
96
97
# File 'lib/next_station/result.rb', line 95

def message
  @message
end

#msg_keysHash (readonly)

Returns:

  • (Hash)


108
109
110
# File 'lib/next_station/result.rb', line 108

def msg_keys
  @msg_keys
end

#typeSymbol (readonly)

The error type.

Examples:

:invalid_input

:not_found

:email_taken

Returns:

  • (Symbol)


88
89
90
# File 'lib/next_station/result.rb', line 88

def type
  @type
end