Class: PuavoRest::SuppressJSONError
- Inherits:
-
Object
- Object
- PuavoRest::SuppressJSONError
- Defined in:
- middleware/suppress_json_errors.rb
Overview
Middleware to suppress Execeptions inherited from JSONError
Instance Method Summary (collapse)
- - (Object) call(env)
-
- (SuppressJSONError) initialize(app)
constructor
A new instance of SuppressJSONError.
Constructor Details
- (SuppressJSONError) initialize(app)
Returns a new instance of SuppressJSONError
6 7 8 |
# File 'middleware/suppress_json_errors.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
- (Object) call(env)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'middleware/suppress_json_errors.rb', line 10 def call(env) begin @app.call(env) rescue JSONError => err if ENV["RACK_ENV"] != "test" = "#{ err }\n#{ err.backtrace.join("\n") }" if STDIN.tty? STDERR.puts .colorize(:red) else STDERR.puts end end [err.http_code, err.headers, [err.to_json]] end end |