88
99import requests
1010from pydantic import ValidationError
11+ from requests import Response
1112
1213from pyartifactory .exception import ArtifactNotFoundError , ArtifactoryError , BadPropertiesError , PropertyNotFoundError
1314from pyartifactory .models .artifact import (
@@ -65,7 +66,8 @@ def info(self, artifact_path: Union[Path, str]) -> ArtifactInfoResponse:
6566 artifact_info = ArtifactFileInfoResponse .model_validate (response .json ())
6667 return artifact_info
6768 except requests .exceptions .HTTPError as error :
68- if error .response .status_code == 404 :
69+ http_response : Union [Response , None ] = error .response
70+ if isinstance (http_response , Response ) and http_response .status_code == 404 :
6971 logger .error ("Artifact %s does not exist" , artifact_path )
7072 raise ArtifactNotFoundError (f"Artifact { artifact_path } does not exist" )
7173 raise ArtifactoryError from error
@@ -174,7 +176,8 @@ def list(
174176 artifact_list : ArtifactListResponse = ArtifactListResponse .model_validate (response .json ())
175177 return artifact_list
176178 except requests .exceptions .HTTPError as error :
177- if error .response .status_code == 404 :
179+ http_response : Union [Response , None ] = error .response
180+ if isinstance (http_response , Response ) and http_response .status_code == 404 :
178181 logger .error ("Artifact %s does not exist" , artifact_path )
179182 raise ArtifactNotFoundError (f"Artifact { artifact_path } does not exist" )
180183 raise ArtifactoryError from error
@@ -196,7 +199,8 @@ def properties(self, artifact_path: str, properties: Optional[List[str]] = None)
196199 logger .debug ("Artifact Properties successfully retrieved" )
197200 return ArtifactPropertiesResponse (** response .json ())
198201 except requests .exceptions .HTTPError as error :
199- if error .response .status_code == 404 :
202+ http_response : Union [Response , None ] = error .response
203+ if isinstance (http_response , Response ) and http_response .status_code == 404 :
200204 raise PropertyNotFoundError (f"Properties { properties } were not found on artifact { artifact_path } " )
201205 raise ArtifactoryError from error
202206
@@ -230,10 +234,11 @@ def set_properties(
230234 logger .debug ("Artifact Properties successfully set" )
231235 return self .properties (artifact_path )
232236 except requests .exceptions .HTTPError as error :
233- if error .response .status_code == 404 :
237+ http_response : Union [Response , None ] = error .response
238+ if isinstance (http_response , Response ) and http_response .status_code == 404 :
234239 logger .error ("Artifact %s does not exist" , artifact_path )
235240 raise ArtifactNotFoundError (f"Artifact { artifact_path } does not exist" )
236- if error . response .status_code == 400 :
241+ if isinstance ( http_response , Response ) and http_response .status_code == 400 :
237242 logger .error ("A property value includes forbidden special characters" )
238243 raise BadPropertiesError ("A property value includes forbidden special characters" )
239244 raise ArtifactoryError from error
@@ -263,7 +268,8 @@ def update_properties(
263268 logger .debug ("Artifact Properties successfully updated" )
264269 return self .properties (artifact_path )
265270 except requests .exceptions .HTTPError as error :
266- if error .response .status_code == 400 :
271+ http_response : Union [Response , None ] = error .response
272+ if isinstance (http_response , Response ) and http_response .status_code == 400 :
267273 logger .error ("Error updating artifact properties" )
268274 raise ArtifactoryError ("Error updating artifact properties" )
269275 raise ArtifactoryError from error
0 commit comments