Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There's no clean way to override the default error formatter #297

Closed
dblock opened this issue Dec 26, 2012 · 1 comment
Closed

There's no clean way to override the default error formatter #297

dblock opened this issue Dec 26, 2012 · 1 comment

Comments

@dblock
Copy link
Member

dblock commented Dec 26, 2012

If you request a format that the API didn't know about, and call error!, you get the default error formatter, which is .txt. Without monkey patching you cannot override it.

module Grape
  module ErrorFormatter
    module Base
      class << self
        def formatter_for(api_format, options = {})
          spec = formatters(options)[api_format]
          case spec
          when nil
            # override here
            Grape::ErrorFormatter::Json
          when Symbol
            method(spec)
          else
            spec
          end
        end
      end
    end
  end
end
@dblock
Copy link
Member Author

dblock commented Dec 27, 2012

Fixed in 81fa919, added default_error_formatter. Setting format will automatically set default_error_formatter since most of the time users just want the format of the errors to match the API format.

@dblock dblock closed this as completed Dec 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant