No commit activity in last 3 years
No release in over 3 years
Rails rack middleware to catch JSON parse errors
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

Rails rack middleware to catch JSON parse errors

Installation

Add this line to your application's Gemfile:

gem 'invalid_json_error_middleware'

And then execute:

$ bundle

Or install it yourself as:

$ gem install invalid_json_error_middleware

Testing

Simply run with rake

rake

Usage

config/application.rb

class Application < Rails::Application
  config.middleware.use InvalidJsonErrorMiddleware
end

For using additional filter checks or/and custom error message:

class Application < Rails::Application
  config.middleware.use InvalidJsonErrorMiddleware, filter_handler: ->(env) { env['HTTP_ACCEPT'] =~ /json/ }, error_handler: ->(error) { "Custom error message: #{error}" }
end

Contributing

Bug reports and pull requests are welcome on GitHub at (invalid_json_error_middleware)[https://github.com/Cisco-AMP/invalid_json_error_middleware]. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Acknowledgements

This project was based off of similar gems such as (rack_middleware_json_error_msg)[https://rubygems.org/gems/rack_middleware_json_error_msg] and (catch_json_parse_errors)[https://rubygems.org/gems/catch_json_parse_errors]. Additionally code and design was taken and modified from (Thoughbot's article here)[https://thoughtbot.com/blog/catching-json-parse-errors-with-custom-middleware].

License

The gem is available as open source under the terms of the MIT License.