Sha256: 93b73101b78034534ffe3869825e5b58b95c424acfbb2f4c4d183cf40b15f306

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Praxis
  module RequestStages

    class ValidatePayload < RequestStage

      attr_reader :parent

      def initialize(name, context, parent:)
        super
        @parent = parent
      end

      def path
        @_path ||= ( @parent.path + [name] )
      end

      def execute
        if request.action.payload
          begin
            request.load_payload(CONTEXT_FOR[:payload])
          rescue => e
            message = "Error loading payload. Used Content-Type: '#{request.content_type}'"
            return validation_handler.handle!(
              exception: e,
              summary: message,
              request: request,
              stage: name
            )
          end

          errors = request.validate_payload(CONTEXT_FOR[:payload])
          if errors.any?
            return validation_handler.handle!(
              summary: "Errors validating payload data",
              errors: errors,
              request: request,
              stage: name
            )
          end
        end
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 lib/praxis/request_stages/validate_payload.rb