{"id":15685266,"url":"https://github.com/prathamesh-sonpatki/bad_json_request_handler","last_synced_at":"2025-05-07T17:25:09.548Z","repository":{"id":62553929,"uuid":"244008084","full_name":"prathamesh-sonpatki/bad_json_request_handler","owner":"prathamesh-sonpatki","description":"Catch bad JSON requests to your application and return valid JSON response back","archived":false,"fork":false,"pushed_at":"2020-10-23T07:50:21.000Z","size":44,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T10:57:50.684Z","etag":null,"topics":["error-handling","json","rails"],"latest_commit_sha":null,"homepage":"https://prathamesh.tech","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prathamesh-sonpatki.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"prathameshs","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-02-29T17:07:03.000Z","updated_at":"2022-09-12T09:13:15.000Z","dependencies_parsed_at":"2022-11-03T05:00:19.077Z","dependency_job_id":null,"html_url":"https://github.com/prathamesh-sonpatki/bad_json_request_handler","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prathamesh-sonpatki%2Fbad_json_request_handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prathamesh-sonpatki%2Fbad_json_request_handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prathamesh-sonpatki%2Fbad_json_request_handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prathamesh-sonpatki%2Fbad_json_request_handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prathamesh-sonpatki","download_url":"https://codeload.github.com/prathamesh-sonpatki/bad_json_request_handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252923670,"owners_count":21825905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error-handling","json","rails"],"created_at":"2024-10-03T17:24:29.985Z","updated_at":"2025-05-07T17:25:09.512Z","avatar_url":"https://github.com/prathamesh-sonpatki.png","language":"Ruby","funding_links":["https://patreon.com/prathameshs"],"categories":[],"sub_categories":[],"readme":"# BadJsonRequestHandler\n\n![Gem Version][gem-version-img]\n\nYou have a Rails API endpoint which expects JSON request payload. But some clients\nsend invalid JSON requests.\nThis typically results in following error.\n\n```\nActionDispatch::Http::Parameters::ParseError: 767: unexpected token at '{ event: { seconds: }}'\n```\n\nThis results in a 500 error from the server. But client does not get an idea that the\nrequest payload was invalid. What if you can instead respond with 400 Bad Request response\nwhich clearly tells the client that the request is invalid. They may start sending valid\nrequests going forward!\n\nThat's where this gem comes into the picture. It captures the `Parameters::ParseError`\nand returns a Bad Request response back. Once you use the initialize from this gem,\nthe response will be as follows.\n\n```\nHTTP 400\n{\"errors\"=\u003e{\"message\"=\u003e\"Invalid request payload: 767: unexpected token at '{ event: { seconds: }}'\"}}\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'bad_json_request_handler'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install bad_json_request_handler\n\n## Usage\n\nThis gem automatically includes `BadJsonRequestHandler` middleware in your Rails application\nby adding it to the middleware stack as follows.\n\n```rb\nRails.application.config.middleware.insert_after ActionDispatch::DebugExceptions, BadJsonRequestHandler::Middleware\n```\n## Development\n\nAfter checking out the repo, run following commands to run the tests.\n\n```rb\nbundle exec appraisal install\nbundle exec appraisal rake test\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/prathamesh-sonpatki/bad_json_request_handler. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/prathamesh-sonpatki/bad_json_request_handler/blob/master/CODE_OF_CONDUCT.md).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the BadJsonRequestHandler project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/prathamesh-sonpatki/bad_json_request_handler/blob/master/CODE_OF_CONDUCT.md).\n\n[gem-version-img]: https://badge.fury.io/rb/bad_json_request_handler.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprathamesh-sonpatki%2Fbad_json_request_handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprathamesh-sonpatki%2Fbad_json_request_handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprathamesh-sonpatki%2Fbad_json_request_handler/lists"}