e2b-dev / E2B

Secure open source cloud runtime for AI apps & AI agents
https://e2b.dev/docs
Apache License 2.0
7.02k stars 458 forks source link

Return correct status code in `error.status` when passing a wrong API key #358

Closed mlejva closed 3 months ago

mlejva commented 7 months ago

When a user passes a wrong API key

try {
    const sandbox = await Sandbox.create({
        apiKey: 'wrong-api-key'
    })
  } catch (error) {
    console.error(error)
    console.error(error.status)
  }

we throw the following error signaling it's an HTTP error with status 401

Error: Error creating sandbox - (401) unauthenticated: Invalid API key, please visit https://e2b.dev/docs?reason=sdk-missing-api-key to get your API key.

but error.status is actually undefined

ValentaTomas commented 3 months ago

This is fixed in the new SDK — now we returning specific AuthenticationError.