Middleware for catching if the post params are not a valid JSON

Hi, We have these clients… that sometimes send us requests that is not a valid JSON. The problem is that this propagates to newrelic as an error and it is not actually an error.

curl -X POST \
    http://localhost:3000/articles.json \
    -H "Content-Type: application/json" \
    -d '{ campaign: { }  }'

In rails < 5.1 we could catch ActionDispatch::ParamsParser::ParseError but with 5.2 ActionDispatch::ParamsParser::ParseError is removed and ActionDispatch::ParamsParser is removed.

I don’t see an alternative.

How do you guys check if the post data is a valid json? Thanks

I got it. I will just catch ActionDispatch::Http::Parameters::ParseError