Skip to content

Commit 61f4c3b

Browse files
committed
Add generic error check
1 parent 0428080 commit 61f4c3b

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515
- Compatibility with `xarray>=2025.03`.
16+
17+
### Changed
1618
- Error message for invalid task ID.
1719

1820
## [2.8.1] - 2025-03-20

Diff for: tidy3d/web/core/exceptions.py

+6
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ class TaskNotFoundError(WebError):
1717
"""Raised when a requested task ID does not exist on the server."""
1818

1919
pass
20+
21+
22+
class WebNotFoundError(WebError):
23+
"""A generic error indicating an HTTP 404 (resource not found)."""
24+
25+
pass

Diff for: tidy3d/web/core/http_util.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626
from .core_config import get_logger
2727
from .environment import Env
28-
from .exceptions import TaskNotFoundError, WebError
28+
from .exceptions import WebError, WebNotFoundError
2929

3030
REINITIALIZED = False
3131

@@ -131,9 +131,7 @@ def wrapper(*args, **kwargs):
131131

132132
if resp.status_code != ResponseCodes.OK.value:
133133
if resp.status_code == ResponseCodes.NOT_FOUND.value:
134-
raise TaskNotFoundError(
135-
"The requested task ID does not exist. Please verify your task ID."
136-
)
134+
raise WebNotFoundError("Resource not found (HTTP 404).")
137135
json_resp = resp.json()
138136
if "error" in json_resp.keys():
139137
raise WebError(json_resp["error"])

Diff for: tidy3d/web/core/task_core.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .constants import SIM_ERROR_FILE, SIM_FILE_HDF5_GZ, SIM_LOG_FILE, SIMULATION_DATA_HDF5_GZ
1818
from .core_config import get_logger_console
1919
from .environment import Env
20-
from .exceptions import WebError
20+
from .exceptions import TaskNotFoundError, WebError, WebNotFoundError
2121
from .file_util import read_simulation_from_hdf5
2222
from .http_util import http
2323
from .s3utils import download_file, download_gz_file, upload_file
@@ -261,7 +261,10 @@ def get(cls, task_id: str, verbose: bool = True) -> SimulationTask:
261261
:class:`.SimulationTask` object containing info about status,
262262
size, credits of task and others.
263263
"""
264-
resp = http.get(f"tidy3d/tasks/{task_id}/detail")
264+
try:
265+
resp = http.get(f"tidy3d/tasks/{task_id}/detail")
266+
except WebNotFoundError:
267+
raise TaskNotFoundError(f"The requested task ID '{task_id}' does not exist.")
265268
task = SimulationTask(**resp) if resp else None
266269
return task
267270

0 commit comments

Comments
 (0)