elevenlabs / elevenlabs-js

The official JavaScript (Node) library for ElevenLabs Text to Speech.
https://elevenlabs.io
MIT License
149 stars 15 forks source link

API Errors are not handled by this SDK #104

Open fernando-playplay opened 1 day ago

fernando-playplay commented 1 day ago

During our tests we noticed that some errors simply do not show if we use the SDK, we only get an http response 400 with elevenLabsClient.audioIsolation.audioIsolation(), but if we call the API directly with https://api.elevenlabs.io/v1/audio-isolation, this is the kind of error object we get: screenshot_2024-11-22_at_16 34 27

We would benefit a lot if you could make it possible to return this kind of error body in the SDK, for instance to use the status to know what happened and show a nice error message for our users.

For the sake of completeness, our code looks like this:

  try {
    return this.client.audioIsolation.audioIsolation({ audio });
  } catch (e) {
    if (e instanceof UnprocessableEntityError) {
      throw new Error(`ElevenLabsError Audio cannot be cleaned ${e}`);
    }
    throw new Error(`ElevenLabsError Unknown error while cleaning audio ${e}`);
  }