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

Better error handling for Wazuh tables #896

Merged
merged 1 commit into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion public/directives/wz-table/wz-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div layout="row" class="md-padding" ng-show="wazuh_table_loading" >
<div class='uil-ring-css'><div></div></div>
</div>
<div layout="row" ng-show="!wazuh_table_loading && items.length">
<div layout="row" ng-show="!error && !wazuh_table_loading && items.length">
<table class="table table-striped table-condensed" style="table-layout: fixed !important" id="wz_table">
<thead class="wz-text-bold">
<th ng-repeat="key in keys" class="wz-text-left"
Expand Down Expand Up @@ -87,6 +87,16 @@
</div>
</div>

<div layout="row" ng-if="error" class="wz-margin-bottom-45">
<div flex class="euiCallOut euiCallOut--warning">
<div class="euiCallOutHeader">
<svg class="euiIcon euiIcon--medium euiCallOutHeader__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><path id="help-a" d="M13.6 12.186l-1.357-1.358c-.025-.025-.058-.034-.084-.056.53-.794.84-1.746.84-2.773a4.977 4.977 0 0 0-.84-2.772c.026-.02.059-.03.084-.056L13.6 3.813a6.96 6.96 0 0 1 0 8.373zM8 15A6.956 6.956 0 0 1 3.814 13.6l1.358-1.358c.025-.025.034-.057.055-.084C6.02 12.688 6.974 13 8 13a4.978 4.978 0 0 0 2.773-.84c.02.026.03.058.056.083l1.357 1.358A6.956 6.956 0 0 1 8 15zm-5.601-2.813a6.963 6.963 0 0 1 0-8.373l1.359 1.358c.024.025.057.035.084.056A4.97 4.97 0 0 0 3 8c0 1.027.31 1.98.842 2.773-.027.022-.06.031-.084.056l-1.36 1.358zm5.6-.187A4 4 0 1 1 8 4a4 4 0 0 1 0 8zM8 1c1.573 0 3.019.525 4.187 1.4l-1.357 1.358c-.025.025-.035.057-.056.084A4.979 4.979 0 0 0 8 3a4.979 4.979 0 0 0-2.773.842c-.021-.027-.03-.059-.055-.084L3.814 2.4A6.957 6.957 0 0 1 8 1zm0-1a8.001 8.001 0 1 0 .003 16.002A8.001 8.001 0 0 0 8 0z"></path></defs><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#help-a" fill-rule="evenodd"></use></svg>
<span class="euiCallOutHeader__title">{{error}}</span>
</div>
</div>
</div>


<div layout="row" ng-if="!wazuh_table_loading && !totalItems" class="wz-margin-top-10">
<span class="color-grey">0 items ({{time | number: 2}} seconds)</span>
</div>
21 changes: 21 additions & 0 deletions public/directives/wz-table/wz-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ app

$scope.nextPage = async currentPage => {
try {
$scope.error = false;
if (
!currentPage &&
$scope.currentPage < $scope.pagedItems.length - 1
Expand All @@ -206,6 +207,8 @@ app
if (!$scope.$$phase) $scope.$digest();
}
} catch (error) {
$scope.wazuh_table_loading = false;
$scope.error = `Error paginating table due to ${error.message || error}. Please refresh your browser.`
errorHandler.handle(
`Error paginating table due to ${error.message || error}`,
'Data factory'
Expand All @@ -229,6 +232,7 @@ app

$scope.sort = async field => {
try {
$scope.error = false;
$scope.wazuh_table_loading = true;
instance.addSorting(field.value || field);
$scope.sortValue = instance.sortValue;
Expand All @@ -237,6 +241,10 @@ app
$scope.wazuh_table_loading = false;
if (!$scope.$$phase) $scope.$digest();
} catch (error) {
$scope.wazuh_table_loading = false;
$scope.error = `Error sorting table by ${
field ? field.value : 'undefined'
}. ${error.message || error}. Please refresh your browser.`
errorHandler.handle(
`Error sorting table by ${
field ? field.value : 'undefined'
Expand All @@ -249,6 +257,7 @@ app

const search = async (term, removeFilters) => {
try {
$scope.error = false;
$scope.wazuh_table_loading = true;
if (removeFilters) instance.removeFilters();
instance.addFilter('search', term);
Expand All @@ -257,6 +266,8 @@ app
$scope.wazuh_table_loading = false;
if (!$scope.$$phase) $scope.$digest();
} catch (error) {
$scope.wazuh_table_loading = false;
$scope.error = `Error searching. ${error.message || error}. Please refresh your browser.`;
errorHandler.handle(
`Error searching. ${error.message || error}`,
'Data factory'
Expand All @@ -267,6 +278,7 @@ app

const filter = async filter => {
try {
$scope.error = false;
$scope.wazuh_table_loading = true;
if (filter.name === 'platform' && instance.path === '/agents') {
const platform = filter.value.split(' - ')[0];
Expand All @@ -281,6 +293,10 @@ app
$scope.wazuh_table_loading = false;
if (!$scope.$$phase) $scope.$digest();
} catch (error) {
$scope.wazuh_table_loading = false;
$scope.error = `Error filtering by ${
filter ? filter.value : 'undefined'
}. ${error.message || error}. Please refresh your browser.`
errorHandler.handle(
`Error filtering by ${
filter ? filter.value : 'undefined'
Expand Down Expand Up @@ -322,13 +338,15 @@ app

const realTimeFunction = async () => {
try {
$scope.error = false;
while (realTime) {
await fetch({ realTime: true, limit: 10 });
if (!$scope.$$phase) $scope.$digest();
await $timeout(1000);
}
} catch (error) {
realTime = false;
$scope.error = `Real time feature aborted. ${error.message || error}. Please refresh your browser.`
errorHandler.handle(
`Real time feature aborted. ${error.message || error}`,
'Data factory'
Expand Down Expand Up @@ -356,12 +374,15 @@ app

const init = async () => {
try {
$scope.error = false;
$scope.wazuh_table_loading = true;
await fetch();
wzTableFilter.set(instance.filters);
$scope.wazuh_table_loading = false;
if (!$scope.$$phase) $scope.$digest();
} catch (error) {
$scope.wazuh_table_loading = false;
$scope.error = `Error while init table. ${error.message || error}. Please refresh your browser.`
errorHandler.handle(
`Error while init table. ${error.message || error}`,
'Data factory'
Expand Down