Skip to content

Instantly share code, notes, and snippets.

@gokure
Created March 5, 2013 07:54
Show Gist options
  • Save gokure/5088676 to your computer and use it in GitHub Desktop.
Save gokure/5088676 to your computer and use it in GitHub Desktop.
# Custom error response of parse json
module MyApp
class ParamsParser < ::ActionDispatch::ParamsParser
def call(env)
super
rescue ::MultiJson::DecodeError
[400, {'Content-Type' => 'application/json'}, [{message: 'JSON parse error'}.to_json]]
end
end
end
MyApp::Application.config.middleware.insert_before ActionDispatch::ParamsParser, MyApp::ParamsParser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment