Sha256: e8a92a1fb31ddb20cd721489b7b39aaa019c04df10d867324640a4e276bc2aaf

Contents?: true

Size: 855 Bytes

Versions: 1

Compression:

Stored size: 855 Bytes

Contents

# frozen_string_literal: true

require "hanami/utils/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)
          Hanami::Utils::Json.parse(body)
        rescue Hanami::Utils::Json::ParserError => e
          raise BodyParsingError.new(e.message)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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