Sha256: f8372d83a459518682a30deb16ff4d8606cdbd5d88ffc323c6724baf5dd3270b

Contents?: true

Size: 824 Bytes

Versions: 2

Compression:

Stored size: 824 Bytes

Contents

# frozen_string_literal: true

require "json"
require_relative "errors"

module Hanami
  module Middleware
    class BodyParser
      # @since 1.3.0
      # @api private
      class JsonParser
        # @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

2 entries across 2 versions & 1 rubygems

Version Path
hanami-router-2.0.0.alpha3 lib/hanami/middleware/body_parser/json_parser.rb
hanami-router-2.0.0.alpha2 lib/hanami/middleware/body_parser/json_parser.rb