Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Handle edge case when response error is string

Jakub Novaka3adcfb05f7e
diff --git a/packages/js-sdk/src/envd/api.ts b/packages/js-sdk/src/envd/api.ts
index 505d10901..d9f2dde54 100644
--- a/packages/js-sdk/src/envd/api.ts
+++ b/packages/js-sdk/src/envd/api.ts
@@ -10,7 +10,7 @@ export async function handleEnvdApiError<A, B, C extends `${string}/${string}`>(
return
}
- const message: string = res.error?.message || await res.response.text()
+ const message: string = typeof res.error == 'string' ? res.error : res.error?.message || await res.response.text()
switch (res.response.status) {
case 400:
diff --git a/packages/python-sdk/e2b/api/client/client.py b/packages/python-sdk/e2b/api/client/client.py
index 38b07d057..63a2493b9 100644
--- a/packages/python-sdk/e2b/api/client/client.py
+++ b/packages/python-sdk/e2b/api/client/client.py
@@ -38,15 +38,9 @@ class Client:
_base_url: str = field(alias="base_url")
_cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
_headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
- _timeout: Optional[httpx.Timeout] = field(
- default=None, kw_only=True, alias="timeout"
- )
- _verify_ssl: Union[str, bool, ssl.SSLContext] = field(
- default=True, kw_only=True, alias="verify_ssl"
- )
- _follow_redirects: bool = field(
- default=False, kw_only=True, alias="follow_redirects"
- )
+ _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
+ _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
+ _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
_httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
_client: Optional[httpx.Client] = field(default=None, init=False)
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
@@ -174,15 +168,9 @@ class AuthenticatedClient:
_base_url: str = field(alias="base_url")
_cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies")
_headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers")
- _timeout: Optional[httpx.Timeout] = field(
- default=None, kw_only=True, alias="timeout"
- )
- _verify_ssl: Union[str, bool, ssl.SSLContext] = field(
- default=True, kw_only=True, alias="verify_ssl"
- )
- _follow_redirects: bool = field(
- default=False, kw_only=True, alias="follow_redirects"
- )
+ _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout")
+ _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl")
+ _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects")
_httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args")
_client: Optional[httpx.Client] = field(default=None, init=False)
_async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
@@ -226,9 +214,7 @@ class AuthenticatedClient:
def get_httpx_client(self) -> httpx.Client:
"""Get the underlying httpx.Client, constructing a new one if not previously set"""
if self._client is None:
- self._headers[self.auth_header_name] = (
- f"{self.prefix} {self.token}" if self.prefix else self.token
- )
+ self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
self._client = httpx.Client(
base_url=self._base_url,
cookies=self._cookies,
@@ -249,9 +235,7 @@ class AuthenticatedClient:
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
self.get_httpx_client().__exit__(*args, **kwargs)
- def set_async_httpx_client(
- self, async_client: httpx.AsyncClient
- ) -> "AuthenticatedClient":
+ def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient":
"""Manually the underlying httpx.AsyncClient
**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
@@ -262,9 +246,7 @@ class AuthenticatedClient:
def get_async_httpx_client(self) -> httpx.AsyncClient:
"""Get the underlying httpx.AsyncClient, constructing a new one if not previously set"""
if self._async_client is None:
- self._headers[self.auth_header_name] = (
- f"{self.prefix} {self.token}" if self.prefix else self.token
- )
+ self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token
self._async_client = httpx.AsyncClient(
base_url=self._base_url,
cookies=self._cookies,
diff --git a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
index 5f1624379..c8385b25d 100644
--- a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
@@ -1,5 +1,4 @@
from typing import Optional, Dict, List
-from httpx import AsyncHTTPTransport
from packaging.version import Version
from e2b.sandbox.sandbox_api import SandboxInfo, SandboxApiBase
@@ -17,8 +16,6 @@ from e2b.api import handle_api_exception
class SandboxApi(SandboxApiBase):
- _transport = AsyncHTTPTransport(limits=SandboxApiBase._limits)
-
@classmethod
async def list(
cls,
@@ -34,7 +31,7 @@ class SandboxApi(SandboxApiBase):
request_timeout=request_timeout,
)
- async with AsyncApiClient(config, transport=cls._transport) as api_client:
+ async with AsyncApiClient(config) as api_client:
res = await get_sandboxes.asyncio_detailed(
client=api_client,
)
@@ -77,7 +74,7 @@ class SandboxApi(SandboxApiBase):
request_timeout=request_timeout,
)
- async with AsyncApiClient(config, transport=cls._transport) as api_client:
+ async with AsyncApiClient(config) as api_client:
res = await delete_sandboxes_sandbox_id.asyncio_detailed(
sandbox_id,
client=api_client,
@@ -108,7 +105,7 @@ class SandboxApi(SandboxApiBase):
request_timeout=request_timeout,
)
- async with AsyncApiClient(config, transport=cls._transport) as api_client:
+ async with AsyncApiClient(config) as api_client:
res = await post_sandboxes_sandbox_id_timeout.asyncio_detailed(
sandbox_id,
client=api_client,
@@ -136,7 +133,7 @@ class SandboxApi(SandboxApiBase):
request_timeout=request_timeout,
)
- async with AsyncApiClient(config, transport=cls._transport) as api_client:
+ async with AsyncApiClient(config) as api_client:
res = await post_sandboxes.asyncio_detailed(
body=NewSandbox(
template_id=template,