Class: FunWithJsonApi::Middleware::CatchJsonApiParseErrors
- Inherits:
-
Object
- Object
- FunWithJsonApi::Middleware::CatchJsonApiParseErrors
- Defined in:
- lib/fun_with_json_api/middleware/catch_json_api_parse_errors.rb
Constant Summary collapse
- JSON_API_REGEX =
%r{application\/vnd\.api\+json}
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ CatchJsonApiParseErrors
constructor
A new instance of CatchJsonApiParseErrors.
Constructor Details
#initialize(app) ⇒ CatchJsonApiParseErrors
Returns a new instance of CatchJsonApiParseErrors.
6 7 8 |
# File 'lib/fun_with_json_api/middleware/catch_json_api_parse_errors.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/fun_with_json_api/middleware/catch_json_api_parse_errors.rb', line 10 def call(env) @app.call(env) rescue ActionDispatch::Http::Parameters::ParseError => error if env['CONTENT_TYPE'] =~ JSON_API_REGEX && respond_with_json_api_error?(env) build_json_api_parse_error_response else raise error end end |