Sha256: c3280997de512d43ae41427182e3c93dc9c3671ce1ccaeb7127be6380e67d4ca

Contents?: true

Size: 833 Bytes

Versions: 5

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true

require "json"
require_relative "parser"

module Hanami
  module Middleware
    class BodyParser
      # @since 1.3.0
      # @api private
      class JsonParser < Parser
        # @since 1.3.0
        # @api private
        def mime_types
          ["application/json", "application/vnd.api+json"]
        end

        # Parse a json string
        #
        # @param body [String] a json string
        #
        # @return [Hash] the parsed json
        #
        # @raise [Hanami::Middleware::BodyParser::BodyParsingError] when the body can't be parsed.
        #
        # @since 1.3.0
        # @api private
        def parse(body)
          JSON.parse(body)
        rescue StandardError => exception
          raise BodyParsingError.new(exception.message)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hanami-router-2.0.0.beta2 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.0.0.beta1 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.0.0.alpha6 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.0.0.alpha5 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.0.0.alpha4 lib/hanami/middleware/body_parser/json_parser.rb