Update check_status to better support different types of errors (#517)

This commit is contained in:
Austin Wang authored and Sai Cheemalapati committed 2017-02-01 23:20:19 -08:00
1 parent 88c22f75e7
commit e9d7e47c75
3 files changed
+53 -5

No files matched your search

+11 -5
View File
@@ -26,7 +26,11 @@ module Google
class ApiCommand < HttpCommand
JSON_CONTENT_TYPE = 'application/json'
FIELDS_PARAM = 'fields'
RATE_LIMIT_ERRORS = %w(rateLimitExceeded userRateLimitExceeded)
ERROR_REASON_MAPPING = {
'rateLimitExceeded' => Google::Apis::RateLimitError,
'userRateLimitExceeded' => Google::Apis::RateLimitError,
'projectNotLinked' => Google::Apis::ProjectNotLinkedError
}
# JSON serializer for request objects
# @return [Google::Apis::Core::JsonRepresentation]
@@ -94,10 +98,12 @@ module Google
error = parse_error(body)
if error
message = sprintf('%s: %s', error['reason'], error['message'])
raise Google::Apis::RateLimitError.new(message,
status_code: status,
header: header,
body: body) if RATE_LIMIT_ERRORS.include?(error['reason'])
raise ERROR_REASON_MAPPING[error['reason']].new(
message,
status_code: status,
header: header,
body: body
) if ERROR_REASON_MAPPING.key?(error['reason'])
end
super(status, header, body, message)
else
+4
View File
@@ -61,6 +61,10 @@ module Google
class RateLimitError < Error
end
# A 403 HTTP error occurred.
class ProjectNotLinkedError < Error
end
# A 401 HTTP error occurred.
class AuthorizationError < Error
end