Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Return `NotFoundError/Exception` for "set timeout" and "get info" 404 errors (#945)

Tomas Valenta17d6e636d101
diff --git a/.changeset/ten-books-clean.md b/.changeset/ten-books-clean.md
new file mode 100644
index 000000000..451da660f
--- /dev/null
+++ b/.changeset/ten-books-clean.md
@@ -0,0 +1,6 @@
+---
+'@e2b/python-sdk': patch
+'e2b': patch
+---
+
+Improve SDK returned errors
diff --git a/packages/js-sdk/src/sandbox/sandboxApi.ts b/packages/js-sdk/src/sandbox/sandboxApi.ts
index dec43ed4f..6599d46e8 100644
--- a/packages/js-sdk/src/sandbox/sandboxApi.ts
+++ b/packages/js-sdk/src/sandbox/sandboxApi.ts
@@ -388,6 +388,10 @@ export class SandboxApi {
signal: config.getSignal(opts?.requestTimeoutMs),
})
+ if (res.error?.code === 404) {
+ throw new NotFoundError(`Sandbox ${sandboxId} not found`)
+ }
+
const err = handleApiError(res)
if (err) {
throw err
@@ -407,6 +411,10 @@ export class SandboxApi {
signal: config.getSignal(opts?.requestTimeoutMs),
})
+ if (res.error?.code === 404) {
+ throw new NotFoundError(`Sandbox ${sandboxId} not found`)
+ }
+
const err = handleApiError(res)
if (err) {
throw err
diff --git a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
index 27015feb6..a41b75f27 100644
--- a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
@@ -77,6 +77,9 @@ class SandboxApi(SandboxBase):
client=api_client,
)
+ if res.status_code == 404:
+ raise NotFoundException(f"Sandbox {sandbox_id} not found")
+
if res.status_code >= 300:
raise handle_api_exception(res)
@@ -140,6 +143,9 @@ class SandboxApi(SandboxBase):
body=PostSandboxesSandboxIDTimeoutBody(timeout=timeout),
)
+ if res.status_code == 404:
+ raise NotFoundException(f"Paused sandbox {sandbox_id} not found")
+
if res.status_code >= 300:
raise handle_api_exception(res)
diff --git a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
index 82104efd2..7052a1e9f 100644
--- a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
@@ -77,6 +77,9 @@ class SandboxApi(SandboxBase):
client=api_client,
)
+ if res.status_code == 404:
+ raise NotFoundException(f"Sandbox {sandbox_id} not found")
+
if res.status_code >= 300:
raise handle_api_exception(res)
@@ -140,6 +143,9 @@ class SandboxApi(SandboxBase):
body=PostSandboxesSandboxIDTimeoutBody(timeout=timeout),
)
+ if res.status_code == 404:
+ raise NotFoundException(f"Sandbox {sandbox_id} not found")
+
if res.status_code >= 300:
raise handle_api_exception(res)