Skip to content

Commit cc37894

Browse files
authored
fix: exists method raises error when no file found (#335)
1 parent 2cc43cf commit cc37894

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

storage3/_async/file_api.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,14 @@ async def exists(
357357
path
358358
The path to the file.
359359
"""
360-
response = await self._request(
361-
"HEAD",
362-
f"/object/info/{self.id}/{path}",
363-
)
364-
return response.status_code == 200
360+
try:
361+
response = await self._request(
362+
"HEAD",
363+
f"/object/{self.id}/{path}",
364+
)
365+
return response.status_code == 200
366+
except json.JSONDecodeError:
367+
return False
365368

366369
async def list(
367370
self,

storage3/_sync/file_api.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,14 @@ def exists(
357357
path
358358
The path to the file.
359359
"""
360-
response = self._request(
361-
"HEAD",
362-
f"/object/info/{self.id}/{path}",
363-
)
364-
return response.status_code == 200
360+
try:
361+
response = self._request(
362+
"HEAD",
363+
f"/object/{self.id}/{path}",
364+
)
365+
return response.status_code == 200
366+
except json.JSONDecodeError:
367+
return False
365368

366369
def list(
367370
self,

0 commit comments

Comments
 (0)