Skip to main content

getLastError

Get the most recent error the hub caught. Most methods do not throw: they log the problem and carry on. This is how you find out afterwards what went wrong.

getLastError(): Error | null;

Parameters​

This method takes no parameters.

Returns​

Error | null: the last error, or null if there has not been one since the hub was created.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();

soundHub.setPan('does-not-exist', 0.5);

const error = soundHub.getLastError();
if (error) {
console.warn('Audio problem:', error.message);
}

Good to know​

  • It is never cleared. A later successful call leaves the old error in place, so compare it with the one you saw before, or listen for error events instead.
  • An error recorded here is also dispatched as an error event (SoundEventsEnum.ERROR) and, except for stream media errors, written to the console with console.error. In debug mode the console line includes the original error object.
  • Load failures are recorded here too, and loadSound also rethrows them, so a try/catch around the load works as well.
  • A media error on a stream is stored with the message Stream error for <id>: ... and dispatched with the stream's soundId, without a console line.

See also​