Sha256: ab31a5b3048325f41ba5a3a33af50f82a7ffd44e836380f0fac468341b82ea4f

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Ftpd

  # All errors (purposefully) generated by this library driver from
  # this class.

  # Any error that send a reply to the client raises a FtpServerError.
  # The message is the text to send (e.g. "Syntax error") and the code
  # is the FTP response code to send (e.g. "502"). This is typically not
  # raised directly, but using the Error mixin.

  class FtpServerError < StandardError
    attr_reader :code

    def initialize(message, code)
      @code = code
      raise ArgumentError, "Invalid response code" unless valid_response_code?

      super(message)
    end

    def message_with_code
      "#{code} #{message}"
    end

    private
    def valid_response_code?
      (400..599).cover?(code)
    end
  end

  # A permanent file system error.  The file isn't there, etc.

  class PermanentFileSystemError < FtpServerError
    def initialize(message, code = 550)
      super
    end

    private
    def valid_response_code?
      (550..559).cover?(code)
    end
  end

  # A transient file system error.  The file is busy, etc.

  class TransientFileSystemError < FtpServerError
    def initialize(message, code = 450)
      super
    end

    private
    def valid_response_code?
      (450..459).cover?(code)
    end
  end

  # A permanent file system error.  Deprecated; use
  # PermanentFileSystemError instead.

  class FileSystemError < PermanentFileSystemError ; end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ftpd-2.1.0 lib/ftpd/exceptions.rb
ftpd-2.0.5 lib/ftpd/exceptions.rb
ftpd-2.0.4 lib/ftpd/exceptions.rb
ftpd-2.0.3 lib/ftpd/exceptions.rb
ftpd-2.0.2 lib/ftpd/exceptions.rb
ftpd-2.0.1 lib/ftpd/exceptions.rb
ftpd-2.0.0 lib/ftpd/exceptions.rb