From 4c9319b67cbd3ed335773ed1d4209b839f697756 Mon Sep 17 00:00:00 2001 From: stve Date: Tue, 3 Mar 2015 01:00:43 -0500 Subject: [PATCH] improve error handling on generic errors --- lib/instapaper/error.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/instapaper/error.rb b/lib/instapaper/error.rb index ea524b6..7be4bcd 100644 --- a/lib/instapaper/error.rb +++ b/lib/instapaper/error.rb @@ -53,11 +53,15 @@ module Instapaper # @param response [HTTP::Response] # @return [Instapaper::Error] def self.from_response(code, path) - 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(ERRORS[code], code) + if ERRORS.keys.include?(code) + new(ERRORS[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', code) + end end end