Skip to content

Commit e75ae01

Browse files
committed
resolve regression in edge filer browser exceptions
1 parent 7b6e428 commit e75ae01

5 files changed

Lines changed: 43 additions & 82 deletions

File tree

cterasdk/cio/edge.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ..objects.uri import unquote
77
from . import common
88
from ..exceptions.transport import HTTPError
9-
from ..exceptions.io import ResourceExistsError, RestrictedPathError
9+
from ..exceptions.io import ResourceExistsError, RestrictedPathError, RemoteStorageError
1010

1111

1212
logger = logging.getLogger('cterasdk.edge')
@@ -70,7 +70,7 @@ def makedir(path):
7070
yield path.absolute
7171
except HTTPError as error:
7272
try:
73-
accept_error(error.response.message.msg, directory)
73+
accept_error(error.error.response.error.msg, path=directory)
7474
except ResourceExistsError:
7575
logger.info('Directory already exists: %s', directory)
7676
logger.info('Directory created: %s', directory)
@@ -127,17 +127,27 @@ def upload(name, destination, fd):
127127
yield param
128128

129129

130-
def accept_error(response, reference):
131-
error = {
132-
"File exists": ResourceExistsError(),
133-
"Creating a folder in this location is forbidden": RestrictedPathError(),
134-
}.get(response, None)
135-
try:
136-
if error:
130+
file_access_errors = {
131+
"File exists": ResourceExistsError,
132+
"Creating a folder in this location is forbidden": RestrictedPathError
133+
}
134+
135+
136+
def accept_error(error_message, **kwargs):
137+
"""
138+
Check if response contains an error.
139+
"""
140+
if error_message not in ['OK']:
141+
exception_classname = file_access_errors.get(error_message, RemoteStorageError)
142+
try:
143+
if exception_classname:
144+
raise exception_classname(**kwargs)
145+
except ResourceExistsError as error:
146+
logger.warning('Resource already exists: a file or folder with this name already exists.')
147+
raise error
148+
except RestrictedPathError as error:
149+
logger.error('Creating a folder in the specified location is forbidden.')
150+
raise error
151+
except RemoteStorageError as error:
152+
logger.error('An error occurred while performing operation.')
137153
raise error
138-
except ResourceExistsError as error:
139-
logger.warning('Resource already exists: a file or folder with this name already exists. %s', {'path': reference})
140-
raise error
141-
except RestrictedPathError as error:
142-
logger.error('Creating a folder in the specified location is forbidden. %s', {'name': reference})
143-
raise error

cterasdk/clients/clients.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def propfind(self, path, depth, **kwargs):
273273
def mkcol(self, path, **kwargs):
274274
request = async_requests.MkcolRequest(self._builder(path), **kwargs)
275275
response = self.request(request, on_error=XMLHandler())
276-
return response.text()
276+
return response.xml()
277277

278278
@decorators.authenticated
279279
def copy(self, source, destination, *, overwrite=False, **kwargs):

cterasdk/clients/errors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import ABC, abstractmethod
22
from http import HTTPStatus
33
from ..exceptions.transport import (
4-
BadRequest, Unauthorized, Forbidden, NotFound, Unprocessable,
4+
BadRequest, Unauthorized, Forbidden, NotFound, NotAllowed, PreConditionFailed, Unprocessable,
55
InternalServerError, BadGateway, ServiceUnavailable, GatewayTimeout, HTTPError
66
)
77
from ..common import Object
@@ -67,6 +67,8 @@ def raise_error(status, error):
6767
HTTPStatus.UNAUTHORIZED: Unauthorized,
6868
HTTPStatus.FORBIDDEN: Forbidden,
6969
HTTPStatus.NOT_FOUND: NotFound,
70+
HTTPStatus.METHOD_NOT_ALLOWED: NotAllowed,
71+
HTTPStatus.PRECONDITION_FAILED: PreConditionFailed,
7072
HTTPStatus.UNPROCESSABLE_ENTITY: Unprocessable,
7173
HTTPStatus.INTERNAL_SERVER_ERROR: InternalServerError,
7274
HTTPStatus.BAD_GATEWAY: BadGateway,

cterasdk/exceptions/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def __init__(self, path):
5050

5151
class RestrictedPathError(RemoteStorageError):
5252

53-
def __init__(self):
54-
super().__init__('Creating a folder in the specified location is forbidden.')
53+
def __init__(self, path):
54+
super().__init__('Creating a folder in the specified location is forbidden.', path)
5555

5656

5757
class RestrictedRoot(RemoteStorageError):

cterasdk/exceptions/transport.py

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,117 +19,66 @@ def __init__(self, status, error):
1919

2020

2121
class BadRequest(HTTPError):
22-
"""
23-
Bad Request
24-
25-
:ivar int code: Status code
26-
:ivar str name: Reason
27-
:ivar cterasdk.clients.errors.Error error: Error object
28-
"""
2922

3023
def __init__(self, error):
3124
super().__init__(HTTPStatus.BAD_REQUEST, error)
3225

3326

3427
class Unauthorized(HTTPError):
35-
"""
36-
Unauthorized
37-
38-
:ivar int code: Status code
39-
:ivar str name: Reason
40-
:ivar cterasdk.clients.errors.Error error: Error object
41-
"""
4228

4329
def __init__(self, error):
4430
super().__init__(HTTPStatus.UNAUTHORIZED, error)
4531

4632

4733
class Forbidden(HTTPError):
48-
"""
49-
Unauthorized
50-
51-
:ivar int code: Status code
52-
:ivar str name: Reason
53-
:ivar cterasdk.clients.errors.Error error: Error object
54-
"""
5534

5635
def __init__(self, error):
5736
super().__init__(HTTPStatus.FORBIDDEN, error)
5837

5938

6039
class NotFound(HTTPError):
61-
"""
62-
NotFound
63-
64-
:ivar int code: Status code
65-
:ivar str name: Reason
66-
:ivar cterasdk.clients.errors.Error error: Error object
67-
"""
6840

6941
def __init__(self, error):
7042
super().__init__(HTTPStatus.NOT_FOUND, error)
7143

7244

73-
class Unprocessable(HTTPError):
74-
"""
75-
Unprocessable
45+
class NotAllowed(HTTPError):
7646

77-
:ivar int code: Status code
78-
:ivar str name: Reason
79-
:ivar cterasdk.clients.errors.Error error: Error object
80-
"""
47+
def __init__(self, error):
48+
super().__init__(HTTPStatus.METHOD_NOT_ALLOWED, error)
49+
50+
51+
class PreConditionFailed(HTTPError):
52+
53+
def __init__(self, error):
54+
super().__init__(HTTPStatus.PRECONDITION_FAILED, error)
55+
56+
57+
class Unprocessable(HTTPError):
8158

8259
def __init__(self, error):
8360
super().__init__(HTTPStatus.UNPROCESSABLE_ENTITY, error)
8461

8562

8663
class InternalServerError(HTTPError):
87-
"""
88-
InternalServerError
89-
90-
:ivar int code: Status code
91-
:ivar str name: Reason
92-
:ivar cterasdk.clients.errors.Error error: Error object
93-
"""
9464

9565
def __init__(self, error):
9666
super().__init__(HTTPStatus.INTERNAL_SERVER_ERROR, error)
9767

9868

9969
class BadGateway(HTTPError):
100-
"""
101-
BadGateway
102-
103-
:ivar int code: Status code
104-
:ivar str name: Reason
105-
:ivar cterasdk.clients.errors.Error error: Error object
106-
"""
10770

10871
def __init__(self, error):
10972
super().__init__(HTTPStatus.BAD_GATEWAY, error)
11073

11174

11275
class ServiceUnavailable(HTTPError):
113-
"""
114-
ServiceUnavailable
115-
116-
:ivar int code: Status code
117-
:ivar str name: Reason
118-
:ivar cterasdk.clients.errors.Error error: Error object
119-
"""
12076

12177
def __init__(self, error):
12278
super().__init__(HTTPStatus.SERVICE_UNAVAILABLE, error)
12379

12480

12581
class GatewayTimeout(HTTPError):
126-
"""
127-
GatewayTimeout
128-
129-
:ivar int code: Status code
130-
:ivar str name: Reason
131-
:ivar cterasdk.clients.errors.Error error: Error object
132-
"""
13382

13483
def __init__(self, error):
13584
super().__init__(HTTPStatus.GATEWAY_TIMEOUT, error)

0 commit comments

Comments
 (0)