Skip to content

Commit

Permalink
Merge pull request #42 from bibixx/feature/add-asset-error-checking
Browse files Browse the repository at this point in the history
Add check for asset loading error
  • Loading branch information
bibixx authored Jan 10, 2021
2 parents 7ca0e0b + dfde054 commit 8b624f7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/AnimateCC/AnimateCC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class AnimateCC extends React.Component<Props, State> {
const loader = new CreateJS.LoadQueue(false);
loader.addEventListener('fileload', (evt) => { this.handleFileLoad(evt as createjs.Event, composition); });
loader.addEventListener('complete', (evt) => { this.handleComplete(evt as createjs.Event, composition); });
loader.addEventListener('error', (evt) => { this.handleFileError(evt as createjs.ErrorEvent); });
loader.loadManifest(manifest);

if (manifest.filter(({ type }) => type === 'image').length === 0) {
Expand Down Expand Up @@ -85,7 +86,21 @@ export class AnimateCC extends React.Component<Props, State> {
this.startAnimation();
};

private handleFileError = (evt: createjs.ErrorEvent) => {
if (evt.title === 'FILE_LOAD_ERROR') {
const { src } = evt.data as { src: string };

log(`Asset ${src} failed to load`);
this.setState({ error: true });
}
};

private handleComplete = (evt: createjs.Event|null, composition: Composition) => {
const { error } = this.state;
if (error) {
return;
}

const {
animationName, paused, getAnimationObject,
} = this.props;
Expand Down

0 comments on commit 8b624f7

Please sign in to comment.