mirror of https://github.com/docker/docker-py.git
Merge 00d1f3177d
into 6e6a273573
This commit is contained in:
commit
8a118243b2
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import os
|
||||
from json import JSONDecodeError
|
||||
|
||||
from .. import auth, errors, utils
|
||||
from ..constants import DEFAULT_DATA_CHUNK_SIZE
|
||||
|
@ -495,7 +496,14 @@ class ImageApiMixin:
|
|||
self._raise_for_status(response)
|
||||
|
||||
if stream:
|
||||
return self._stream_helper(response, decode=decode)
|
||||
try:
|
||||
for line in self._stream_helper(response, decode=decode):
|
||||
if isinstance(line, dict) and "errorDetail" in line:
|
||||
message = line["errorDetail"]["message"]
|
||||
raise errors.APIError(message=message)
|
||||
yield line
|
||||
except JSONDecodeError as e:
|
||||
raise JSONDecodeError("Error decoding response stream") from e
|
||||
|
||||
return self._result(response)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import pytest
|
|||
|
||||
import docker
|
||||
from docker import auth
|
||||
import docker.errors
|
||||
|
||||
from . import fake_api
|
||||
from .api_test import (
|
||||
|
@ -288,6 +289,12 @@ class ImageTest(BaseAPIClientTest):
|
|||
timeout=DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_push_image_with_exception(self):
|
||||
with pytest.raises(Exception):
|
||||
self.client.push("docker", stream=True, tag='tag', decode=True)
|
||||
self.fail('An exception should have been raised')
|
||||
|
||||
|
||||
def test_tag_image(self):
|
||||
self.client.tag(fake_api.FAKE_IMAGE_ID, fake_api.FAKE_REPO_NAME)
|
||||
|
||||
|
|
Loading…
Reference in New Issue