6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/docker/remote/utils.rb', line 6
def potentially_raise_error!(response)
case response.code.to_i
when 401
raise UnauthorizedError, "401 Unauthorized: #{response.message}"
when 404
json = JSON.parse(response.body) rescue {}
error = (json['errors'] || []).first || {}
if error['code'] == 'NAME_UNKNOWN'
raise UnknownRepoError, error['message']
end
raise NotFoundError, "404 Not Found: #{response.message}"
end
case response.code.to_i / 100
when 4
raise ClientError, "#{response.code}: #{response.message}"
when 5
raise ServerError, "#{response.code}: #{response.message}"
end
end
|