Sha256: 8fd7b846aeaf92c2cbccf4b9b4b63cd07d1ad8498f08a7a344e72d7905eaaea1

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

module RestPack
  class Service < Mutations::Command
    attr_accessor :response

    def run
      @response = Response.new

      begin
        init
        mutation = super

        if mutation.errors
          mutation.errors.message.each do |error|
            @response.add_error(error[0], error[1].gsub(error[0].capitalize, ''))
          end

          @response.status ||= :unprocessable_entity
        else
          @response.status ||= :ok
        end

        if @response.status == :ok
          @response.result = mutation.result if mutation.result
        end
      rescue Exception => e
        p e.message #TODO: GJ: logging

        @response.add_error(:base, 'Service Error')
        @response.status = :internal_service_error
      end

      @response
    end

    def init
    end

    def status(status)
      @response.status = status
    end

    def valid?
      !has_errors?
    end

    def service_error(message)
      field_error :base, message
    end

    def field_error(key, message)
      add_error key, key, message
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
restpack_service-0.0.24 lib/restpack_service/service.rb
restpack_service-0.0.21 lib/restpack_service/service.rb
restpack_service-0.0.20 lib/restpack_service/service.rb
restpack_service-0.0.19 lib/restpack_service/service.rb
restpack_service-0.0.18 lib/restpack_service/service.rb
restpack_service-0.0.17 lib/restpack_service/service.rb
restpack_service-0.0.16 lib/restpack_service/service.rb
restpack_service-0.0.8 lib/restpack_service/service.rb
restpack_service-0.0.7 lib/restpack_service/service.rb
restpack_service-0.0.5 lib/restpack_service/service.rb