def parsed_body
      request_media_type = request.media_type
      unless request_media_type =~ /\S/
        fallback = true
        request_media_type = supported_media_types.first
      end
      case request_media_type
      when 'application/json'
        begin
          return JSON.parse(request_body)
        rescue JSON::ParserError
          if fallback
            t_key = 'app.errors.request.body_parse_fallback_json'
            default = "Error encountered attempting to parse the request body. No Content-Type was specified and parsing as JSON failed. Supported media types are %{supported_media_types}. JSON parser error: %{error_class}: %{error_message}"
          else
            t_key = 'app.errors.request.body_parse_indicated_json'
            default = "Error encountered attempting to parse the JSON request body: %{error_class}: %{error_message}"
          end
          message = I18n.t(t_key,
            :default => default,
            :error_class => $!.class,
            :error_message => $!.message,
            :supported_media_types => supported_media_types.join(', ')
          )
          errors = {'json' => [message]}
          halt_error(400, errors)
        end
      else
        if supported_media_types.include?(request_media_type)
          # :nocov:
          raise NotImplementedError, "handling request body with media type #{request_media_type} not implemented"
          # :nocov:
        end
        logger.error "received Content-Type of #{request.content_type.inspect}; halting with 415"
        message = I18n.t('app.errors.request.content_type',
          :default => "Unsupported Content-Type of %{content_type} given for the request body. Supported media types are %{supported_media_types}",
          :content_type => request.content_type,
          :supported_media_types => supported_media_types.join(', ')
        )
        errors = {'Content-Type' => [message]}
        halt_error(415, errors)
      end
    end
def parsed_body
      request_media_type = request.media_type
      unless request_media_type =~ /\S/
        fallback = true
        request_media_type = supported_media_types.first
      end
      case request_media_type
      when 'application/json'
        begin
          return JSON.parse(request_body)
        rescue JSON::ParserError
          if fallback
            t_key = 'app.errors.request.body_parse_fallback_json'
            default = "Error encountered attempting to parse the request body. No Content-Type was specified and parsing as JSON failed. Supported media types are %{supported_media_types}. JSON parser error: %{error_class}: %{error_message}"
          else
            t_key = 'app.errors.request.body_parse_indicated_json'
            default = "Error encountered attempting to parse the JSON request body: %{error_class}: %{error_message}"
          end
          message = I18n.t(t_key,
            :default => default,
            :error_class => $!.class,
            :error_message => $!.message,
            :supported_media_types => supported_media_types.join(', ')
          )
          errors = {'json' => [message]}
          halt_error(400, errors)
        end
      else
        if supported_media_types.include?(request_media_type)
          # :nocov:
          raise NotImplementedError, "handling request body with media type #{request_media_type} not implemented"
          # :nocov:
        end
        logger.error "received Content-Type of #{request.content_type.inspect}; halting with 415"
        message = I18n.t('app.errors.request.content_type',
          :default => "Unsupported Content-Type of %{content_type} given for the request body. Supported media types are %{supported_media_types}",
          :content_type => request.content_type,
          :supported_media_types => supported_media_types.join(', ')
        )
        errors = {'Content-Type' => [message]}
        halt_error(415, errors)
      end
    end
returns the parsed contents of the request body.

 checks the Content-Type of the request, and unless it's supported (or omitted - in which case assumed to be the
 first supported media type), halts with 415.

 if the body is not parseable, then halts with 400.