Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/ten-books-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@e2b/python-sdk': patch
'e2b': patch
---

Improve SDK returned errors
8 changes: 8 additions & 0 deletions packages/js-sdk/src/sandbox/sandboxApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions packages/python-sdk/e2b/sandbox_async/sandbox_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ async def _cls_get_info(
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)

Expand Down Expand Up @@ -140,6 +143,9 @@ async def _cls_set_timeout(
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)

Expand Down
6 changes: 6 additions & 0 deletions packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def _cls_get_info(
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)

Expand Down Expand Up @@ -140,6 +143,9 @@ def _cls_set_timeout(
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)

Expand Down