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
errorevents instead. - An error recorded here is also dispatched as an
errorevent (SoundEventsEnum.ERROR) and, except for stream media errors, written to the console withconsole.error. In debug mode the console line includes the original error object. - Load failures are recorded here too, and
loadSoundalso rethrows them, so atry/catcharound 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'ssoundId, without a console line.
See also
addEventListener: listen forerrorevents as they happen.setDebugMode: log more detail to the console.soundEvents: the full list of events,errorincluded.