class Instapaper::Error

Custom error class for rescuing from all Instapaper errors

Constants

BOOKMARK_ERRORS
BookmarkError
CLIENT_ERRORS
CODES
ClientError
FOLDER_ERRORS
FolderError
HIGHLIGHT_ERRORS
HTTP_ERRORS
HighlightError
OAuthError
SERVER_ERRORS
SERVICE_ERRORS
ServerError
ServiceUnavailableError

Attributes

code[R]

@return [Integer]

Public Class Methods

from_response(code, path) click to toggle source

Create a new error from an HTTP response

@param response [HTTP::Response] @return [Instapaper::Error]

# File lib/instapaper/error.rb, line 78
def self.from_response(code, path)
  if (HTTP_ERRORS.keys + SERVICE_ERRORS.keys).include?(code)
    from_response_code(code)
  else
    case path
    when /highlights/ then HighlightError.new(HIGHLIGHT_ERRORS[code], code)
    when /bookmarks/ then BookmarkError.new(BOOKMARK_ERRORS[code], code)
    when /folders/ then FolderError.new(FOLDER_ERRORS[code], code)
    else new('Unknown Error', code)
    end
  end
end
from_response_code(code) click to toggle source

Create a new error from an HTTP response code

@param code [Integer] @return [Instapaper::Error]

# File lib/instapaper/error.rb, line 95
def self.from_response_code(code)
  if CLIENT_ERRORS.keys.include?(code)
    ClientError.new(CLIENT_ERRORS[code], code)
  elsif SERVER_ERRORS.keys.include?(code)
    ServerError.new(SERVER_ERRORS[code], code)
  elsif SERVICE_ERRORS.keys.include?(code)
    new(SERVICE_ERRORS[code], code)
  end
end
new(message = '', code = nil) click to toggle source

Initializes a new Error object

@param message [Exception, String] @param code [Integer] @return [Instapaper::Error]

Calls superclass method
# File lib/instapaper/error.rb, line 110
def initialize(message = '', code = nil)
  super(message)
  @code = code
end