Sha256: 4822acca763f9d62ce6a79831c749de85cc73d396585faf0290853e3bf4f32db

Contents?: true

Size: 841 Bytes

Versions: 11

Compression:

Stored size: 841 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 self.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

11 entries across 11 versions & 1 rubygems

Version Path
hanami-router-2.2.0 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.2.0.rc1 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.2.0.beta2 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.2.0.beta1 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.1.0 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.1.0.rc3 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.1.0.rc2 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.1.0.rc1 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.1.0.beta1 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.0.2 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.0.1 lib/hanami/middleware/body_parser/json_parser.rb