Exception: JsonHttpError
- Inherits:
-
StandardError
- Object
- StandardError
- JsonHttpError
- Defined in:
- lib/json_http_error.rb
Constant Summary collapse
- VERSION =
'0.0.2'.freeze
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.
6 7 8 9 |
# File 'lib/json_http_error.rb', line 6 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.
4 5 6 |
# File 'lib/json_http_error.rb', line 4 def code @code end |
#opts ⇒ Object
Returns the value of attribute opts.
4 5 6 |
# File 'lib/json_http_error.rb', line 4 def opts @opts end |
Instance Method Details
#reply ⇒ Object
15 16 17 18 19 |
# File 'lib/json_http_error.rb', line 15 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
21 22 23 24 25 26 27 |
# File 'lib/json_http_error.rb', line 21 def to_proc binded_reply = reply binded_code = code Proc.new do render status: binded_code, json: { error: binded_reply } end end |