Sha256: c341e68c069eda0907261ae2cf0b7d81ddb0c44ce49ae15602b901a99fceccf2

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

module Rmega
  class ApiRequestError < StandardError
    attr_reader :code

    def initialize error_code
      @code = error_code
      error_description = self.class.all_messages[@code]
      super "Received error code #{@code}. #{error_description}".strip
    end

    def self.is_error_code? number
      !!Integer(number) rescue false
    end

    def self.all_messages
      {
        -1  => 'An internal error has occurred. Please submit a bug report, detailing the exact circumstances in which this error occurred.',
        -2  => 'You have passed invalid arguments to this command.',
        -3  => 'A temporary congestion or server malfunction prevented your request from being processed. No data was altered. Retry. Retries must be spaced with exponential backoff.',
        -4  => 'You have exceeded your command weight per time quota. Please wait a few seconds, then try again (this should never happen in sane real-life applications).',
        -5  => 'The upload failed. Please restart it from scratch.',
        -6  => 'Too many concurrent IP addresses are accessing this upload target URL.',
        -7  => 'The upload file packet is out of range or not starting and ending on a chunk boundary.',
        -8  => 'The upload target URL you are trying to access has expired. Please request a fresh one.',
        -9  => 'Object (typically, node or user) not found',
        -10 => 'Circular linkage attempted',
        -11 => 'Access violation (e.g., trying to write to a read-only share)',
        -12 => 'Trying to create an object that already exists',
        -13 => 'Trying to access an incomplete resource',
        -14 => 'A decryption operation failed (never returned by the API)',
        -15 => 'Invalid or expired user session, please relogin',
        -16 => 'User blocked',
        -17 => 'Request over quota',
        -18 => 'Resource temporarily not available, please try again later'
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rmega-0.0.3 lib/rmega/api_request_error.rb