Sha256: dab3399a003a35c8456f138240ffb946af3b3b56d5c77d3e2b92bcb954847a09

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

module Apipie

  class Error < StandardError
  end

  class ParamError < Error
  end

  class UnknownCode < Error
  end

  class ReturnsMultipleDefinitionError < Error
    def to_s
      "a 'returns' statement cannot indicate both array_of and type"
    end
  end

  # abstract
  class DefinedParamError < ParamError
    attr_accessor :param

    def initialize(param)
      @param = param
    end
  end

  class ParamMissing < DefinedParamError
    def to_s
      unless @param.options[:missing_message].nil?
        if @param.options[:missing_message].kind_of?(Proc)
          @param.options[:missing_message].call
        else
          @param.options[:missing_message].to_s
        end
      else
        "Missing parameter #{@param.name}"
      end
    end
  end

  class UnknownParam < DefinedParamError
    def to_s
      "Unknown parameter #{@param}"
    end
  end

  class ParamInvalid < DefinedParamError
    attr_accessor :value, :error

    def initialize(param, value, error)
      super param
      @value = value
      @error = error
    end

    def to_s
      "Invalid parameter '#{@param}' value #{@value.inspect}: #{@error}"
    end
  end

  class ResponseDoesNotMatchSwaggerSchema < Error
    def initialize(controller_name, method_name, response_code, error_messages, schema, returned_object)
      super("Response does not match swagger schema (#{controller_name}##{method_name} #{response_code}): #{error_messages}\nSchema: #{JSON(schema)}\nReturned object: #{returned_object}")
    end
  end

  class NoDocumentedMethod < Error
    def initialize(controller_name, method_name)
      super("There is no documented method #{controller_name}##{method_name}")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
apipie-rails-1.2.0 lib/apipie/errors.rb
apipie-rails-1.1.0 lib/apipie/errors.rb
apipie-rails-1.0.0 lib/apipie/errors.rb
apipie-rails-0.9.4 lib/apipie/errors.rb