Exception: JsonHttpError
- Inherits:
-
StandardError
- Object
- StandardError
- JsonHttpError
- Defined in:
- lib/json_http_error.rb,
lib/json_http_error/railtie.rb
Defined Under Namespace
Classes: Railtie
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(error_code, error_opts = {}) ⇒ JsonHttpError
constructor
A new instance of JsonHttpError.
- #reply ⇒ Object
- #to_proc ⇒ Object
Constructor Details
#initialize(error_code, error_opts = {}) ⇒ JsonHttpError
Returns a new instance of JsonHttpError.
4 5 6 7 |
# File 'lib/json_http_error.rb', line 4 def initialize(error_code, error_opts = {}) @code = error_code @opts = error_opts.with_indifferent_access end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
2 3 4 |
# File 'lib/json_http_error.rb', line 2 def code @code end |
#opts ⇒ Object
Returns the value of attribute opts.
2 3 4 |
# File 'lib/json_http_error.rb', line 2 def opts @opts end |
Instance Method Details
#reply ⇒ Object
13 14 15 16 17 |
# File 'lib/json_http_error.rb', line 13 def reply reply = { status: 'ERROR', code: code, message: I18n.t("http_status.#{code}", opts) } reply = reply.merge(opts[:json]) if opts[:json] reply end |
#to_proc ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/json_http_error.rb', line 19 def to_proc binded_reply = reply binded_code = code Proc.new do render status: binded_code, json: { error: binded_reply } end end |