I want to use the status returned by the useRiveFile hook to fail gracefully if there is an error while loading the file, e.g. if the file at src is missing.
I think similarly, useRiveFile should also catch errors thrown by new RiveFile. Without this error handling, I don't think I can use useRiveFile in production.
I want to use the
status
returned by theuseRiveFile
hook to fail gracefully if there is an error while loading the file, e.g. if the file atsrc
is missing.Currently, if there is an error during the
initData
method ofRiveFile
, firing theloadError
event is immediately followed by throwing an Error (https://github.com/rive-app/rive-wasm/blob/55691eb4893e3056f2d5096fbc3f2e58142e8d79/js/src/rive.ts#L1453-L1457).This makes the
status
returned byuseRiveFile
provide little value for this use case, since ifstatus === 'failed'
, the app is going to crash anyways.This is not an issue when using
useRive
withoutuseRiveFile
, because the call tonew RiveFile
is wrapped in a try / catch in theRive
constructor (https://github.com/rive-app/rive-wasm/blob/55691eb4893e3056f2d5096fbc3f2e58142e8d79/js/src/rive.ts#L1817-L1824).I think similarly,
useRiveFile
should also catch errors thrown bynew RiveFile
. Without this error handling, I don't think I can useuseRiveFile
in production.Other work-arounds also welcome!
Thank you!