Skip to content

Commit

Permalink
fix(core): 🐛 filter transition errors from request errors
Browse files Browse the repository at this point in the history
Closes #475
  • Loading branch information
thierrymichel committed Dec 9, 2019
1 parent 0801276 commit 281c85f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export class Core {
// TODO: manage / use cases for cancellation
// this.logger.debug('Transition cancelled');

// If no debug mode, force back.
// If transition error and no debug mode, force reload page.
/* istanbul ignore else */
if (Logger.getLevel() === 0) {
this.force(data.current.url.href);
Expand Down
31 changes: 28 additions & 3 deletions packages/core/src/modules/Transitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ export class Transitions {
} catch (error) {
// this.logger.debug('Transition error [sync]');
// this.logger.error(error);
throw new BarbaError(error, 'Transition error [sync]');
if (this._isTransitionError(error)) {
throw new BarbaError(error, 'Transition error [sync]');
}
}
} else {
let leaveResult: any = false;
Expand All @@ -203,7 +205,12 @@ export class Transitions {
} catch (error) {
// this.logger.debug('Transition error [before/after/leave]');
// this.logger.error(error);
throw new BarbaError(error, 'Transition error [before/after/leave]');
if (this._isTransitionError(error)) {
throw new BarbaError(
error,
'Transition error [before/after/leave]'
);
}
}

try {
Expand All @@ -219,7 +226,12 @@ export class Transitions {
} catch (error) {
// this.logger.debug('Transition error [before/after/enter]');
// this.logger.error(error);
throw new BarbaError(error, 'Transition error [before/after/enter]');
if (this._isTransitionError(error)) {
throw new BarbaError(
error,
'Transition error [before/after/enter]'
);
}
}
}

Expand Down Expand Up @@ -297,6 +309,19 @@ export class Transitions {
hooks.do('currentRemoved', data);
}

private _isTransitionError(error: any) {
if (error.message) {
// Errors from request
return !/Timeout error|Fetch error/.test(error.message);
}
if (error.status) {
// Errors from request
return false;
}

return true;
}

/**
* Do hooks + async transition methods.
*/
Expand Down

0 comments on commit 281c85f

Please sign in to comment.