Module: Miscellany::HttpErrorHandling::ClassMethods
- Defined in:
- lib/miscellany/controller/http_error_handling.rb
Instance Method Summary collapse
- #http_error(status = 400, message = nil, &blk) ⇒ Object
- #rescue_with_http_error(*errors, status: nil, message: nil, **kwargs) ⇒ Object
Instance Method Details
#http_error(status = 400, message = nil, &blk) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/miscellany/controller/http_error_handling.rb', line 26 def http_error(status = 400, = nil, &blk) = blk if blk.present? lambda { |err| # This is necessary to ensure that HttpErrors are never handled as StandardErrors if err.is_a?(HttpError) render_http_error(err) else render_http_error(err, status: status, message: ) end } end |
#rescue_with_http_error(*errors, status: nil, message: nil, **kwargs) ⇒ Object
38 39 40 |
# File 'lib/miscellany/controller/http_error_handling.rb', line 38 def rescue_with_http_error(*errors, status: nil, message: nil, **kwargs) rescue_from(*errors, with: http_error(status, ), **kwargs) end |