jnunemaker/httparty · error · NotImplementedError

#{self.class.name} has not implemented a parsing method for

Error message

#{self.class.name} has not implemented a parsing method for the #{format.inspect} format.

What it means

The response parser raises NotImplementedError when the request format maps to a method the parser class does not define. parse_supported_format does `send(format)` only if the parser responds_to?(format, true); a custom parser class set via `parser MyParser` that does not inherit HTTParty::Parser (or overrides method_missing-prone APIs without defining json/xml/etc.) triggers this at response-parse time, i.e. after the HTTP call already succeeded.

Source

Thrown at lib/httparty/parser.rb:153

    end

    def html
      body
    end

    def plain
      body
    end

    def supports_format?
      self.class.supports_format?(format)
    end

    def parse_supported_format
      if respond_to?(format, true)
        send(format)
      else
        raise NotImplementedError, "#{self.class.name} has not implemented a parsing method for the #{format.inspect} format."
      end
    end
  end
end

View on GitHub (pinned to 8f4a09e343)

Solutions

  1. Inherit from HTTParty::Parser and override only what you need, calling super for other formats.
  2. Define the missing method on the custom parser: `def json; JSON.parse(body); end`.
  3. Declare `SupportedFormats` on the custom parser restricted to what it really parses so mismatched Content-Types fall back to plain.

Example fix

# before
class EnvelopeParser
  def self.call(body, _fmt = nil)
    JSON.parse(body)['data']
  end
end
class Client
  include HTTParty
  parser EnvelopeParser
end
# -> NotImplementedError: EnvelopeParser has not implemented a parsing method for the :json format

# after
class EnvelopeParser < HTTParty::Parser
  def json
    JSON.parse(body)['data']
  end
end
Defensive patterns

Strategy: validation

Validate before calling

class EnvelopeParser < HTTParty::Parser
  def json; JSON.parse(body)['data']; end
end
raise NotImplementedError, 'parser missing json' unless EnvelopeParser.method_defined?(:json)

Type guard

parses_format = ->(fmt, klass) { klass.method_defined?(fmt.to_s) }

Try / catch

begin
  Client.get(url)
rescue NotImplementedError => e
  raise unless e.message.include?('parsing method')
  Client.get(url, format: :plain).tap { |r| JSON.parse(r.body)['data'] }
end

Prevention

When it happens

Trigger: `parser MyParser` plus `format :json` where MyParser defines neither a class-level call format_from_mimetype nor an instance `json` method; subclassing HTTParty::Parser but renaming or omitting the format methods; a parser that handles only csv while the response Content-Type resolves to :json.

Common situations: Writing custom parsers for enveloped APIs (e.g. { data: ..., meta: ... }) and forgetting to define every format the client may request, upgrading httparty where formats like csv were added, and environment-dependent Content-Types (an error page with text/html hitting a JSON-only custom parser).

Related errors


AI-assisted analysis of jnunemaker/httparty@8f4a09e343 (2026-08-21). Data as JSON: /api/errors/6995be3561f8fa39. Report an issue: GitHub.