Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CatchJsonParseErrors
- def initialize(app)
- @app = app
- end
- def call(env)
- begin
- @app.call(env)
- rescue ActionDispatch::ParamsParser::ParseError => error
- if env['HTTP_ACCEPT'] =~ /application/json/
- error_output = "There was a problem in the JSON: #{error}"
- return [
- 400, { "Content-Type" => "application/json" },
- [ { status: 400, error: error_output }.to_json ]
- ]
- else
- raise error
- end
- end
- end
- end
- config.middleware.insert_before ActionDispatch::ParamsParser, "CatchJsonParseErrors"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement