Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error event reported correctly in lazy CSRF mode #770

Merged
merged 2 commits into from
Oct 3, 2019

Conversation

tomasherceg
Copy link
Member

The PR #768 fixed the error event to be triggered correctly when the application is offline, however it didn't worked in lazy CSRF mode - when the CSRF token couldn't be obtained, it crashed without invoking such event.

This PR should fix this in lazy CSRF mode and cover this functionality with UI test making sure that all kinds of client-server communication will either succeed or raise the error event:

  • command
  • staticCommand
  • SPA navigation

We should consider renaming the UI test to OfflineMode or something like this as it is not related only to SPA navigation.

UI tests for Offline error event extended for the lazy CSRF case
src/DotVVM.Framework/Resources/Scripts/DotVVM.ts Outdated Show resolved Hide resolved
Comment on lines +391 to +400
var csrfToken;
try {
csrfToken = await this.fetchCsrfToken(viewModelName);
}
catch (err) {
this.events.error.trigger(new DotvvmErrorEventArgs(sender, this.viewModels[viewModelName].viewModel, viewModelName, null, null));
console.warn(`CSRF token fetch failed.`);
errorCallback({ error: err });
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might have been cleaner to use await this.fetchCsrfToken(viewModelName).catch(err => ...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't knew about that, but still - I need to use return in the catch clause so it doesn't help much here.

@tomasherceg tomasherceg merged commit 60ba688 into master Oct 3, 2019
@tomasherceg tomasherceg deleted the fix/offline-error-event branch October 3, 2019 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants