Exception: Pendragon::Errors::Base
- Inherits:
-
StandardError
- Object
- StandardError
- Pendragon::Errors::Base
- Defined in:
- lib/pendragon/errors.rb
Overview
Class for handling HTTP error.
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#message ⇒ Object
Returns the value of attribute message.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
-
.create(**options, &block) ⇒ Class
Creates a new error class.
-
.default_headers ⇒ Hash{String => String}
Returns default headers.
-
.default_message ⇒ String
Returns default message.
Instance Method Summary collapse
-
#initialize(headers: {}, status: self.class.status, message: self.class.default_message, **payload) ⇒ Pendragon::Errors::Base
constructor
Constructs an instance of Errors::Base.
-
#to_response ⇒ Array<Integer, Hash{String => String}, #each>
Converts self into response conformed Rack style.
Constructor Details
#initialize(headers: {}, status: self.class.status, message: self.class.default_message, **payload) ⇒ Pendragon::Errors::Base
Constructs an instance of Errors::Base
50 51 52 53 54 55 |
# File 'lib/pendragon/errors.rb', line 50 def initialize(headers: {}, status: self.class.status, message: self.class., **payload) self.headers = self.class.default_headers.merge(headers) self.status, self. = status, parse_payload(**payload) if payload.kind_of?(Hash) && respond_to?(:parse_payload) super() end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
8 9 10 |
# File 'lib/pendragon/errors.rb', line 8 def headers @headers end |
#message ⇒ Object
Returns the value of attribute message.
8 9 10 |
# File 'lib/pendragon/errors.rb', line 8 def @message end |
#status ⇒ Object
Returns the value of attribute status.
8 9 10 |
# File 'lib/pendragon/errors.rb', line 8 def status @status end |
Class Method Details
.create(**options, &block) ⇒ Class
Creates a new error class.
21 22 23 24 25 26 |
# File 'lib/pendragon/errors.rb', line 21 def self.create(**, &block) Class.new(self) do .each { |k, v| define_singleton_method(k) { v } } class_eval(&block) if block_given? end end |
.default_headers ⇒ Hash{String => String}
Returns default headers.
39 40 41 |
# File 'lib/pendragon/errors.rb', line 39 def self.default_headers @default_headers ||= { 'Content-Type' => 'text/plain' } end |
.default_message ⇒ String
Returns default message.
32 33 34 |
# File 'lib/pendragon/errors.rb', line 32 def self. @default_message ||= Rack::Utils::HTTP_STATUS_CODES.fetch(status, 'server error').downcase end |
Instance Method Details
#to_response ⇒ Array<Integer, Hash{String => String}, #each>
Converts self into response conformed Rack style.
60 61 62 |
# File 'lib/pendragon/errors.rb', line 60 def to_response [status, headers, []] end |