Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/discogs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Discogs::UnknownResource < StandardError; end
class Discogs::InternalServerError < StandardError; end
class Discogs::AuthenticationError < StandardError; end
class Discogs::RateLimitError < StandardError; end
class Discogs::UnknownServerError < StandardError; end

# Loading sequence.
require File.dirname(__FILE__) + "/discogs/wrapper"
16 changes: 12 additions & 4 deletions lib/discogs/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,14 @@ def query_and_build(path, params={}, method=:get, body=nil)
def query_api(path, params={}, method=:get, body=nil)
response = make_request(path, params, method, body)

raise_unknown_resource(path) if response.code == "404"
raise_authentication_error(path) if response.code == "401"
raise_rate_limit_error(path) if response.code == "429"
raise_internal_server_error if response.code == "500"
raise_unknown_resource(path) if response.code == 404
raise_authentication_error(path) if response.code == 401
raise_rate_limit_error(path) if response.code == 429
raise_internal_server_error if response.code == 500
if response.code >= 300
puts response.inspect
raise_unknown_server_error(response.code)
end

# Unzip the response data, or just read it in directly
# if the API responds without gzipping.
Expand Down Expand Up @@ -853,6 +857,10 @@ def raise_internal_server_error
raise Discogs::InternalServerError, "The API server cannot complete the request"
end

def raise_unknown_server_error(code="")
raise Discogs::UnknownServerError, "Server returned unexpected response: #{code}"
end

def raise_authentication_error(path="")
raise Discogs::AuthenticationError, "Authentication is required for this resource: #{path}"
end
Expand Down