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

Implement try-catch strategy on all front services #3265

Closed
25 tasks done
frankeros opened this issue May 19, 2021 · 1 comment
Closed
25 tasks done

Implement try-catch strategy on all front services #3265

frankeros opened this issue May 19, 2021 · 1 comment

Comments

@frankeros
Copy link
Contributor

frankeros commented May 19, 2021

Parent Issue Blocked by
#3271 #3262

Description
In order to improve better error handling in the front-end, we should implement a better try-catch strategy in all services and functions.

Acceptance Criteria

  • An error must be handled for every business function, and log it then throw it again until the top component or class.
  • Each function could add to the original error some metadata (id, origin, etc) but not remove properties or replace values.
  • An NO business error only must be displayed or not by the new component of Implement a client-side logging #3262.
  • All business errors should be displayed by the component by self.
  • If the service or function is no used remove it.

Tasks:

@frankeros frankeros changed the title Implement try-catch strategy on all react-services Implement try-catch strategy on all front services May 19, 2021
@frankeros frankeros added the pending-PO Taks pending for PO validation and priorization label May 20, 2021
@Machi3mfl Machi3mfl self-assigned this Jun 9, 2021
@frankeros frankeros removed the question label Jun 9, 2021
@Machi3mfl
Copy link
Member

Machi3mfl commented Jun 9, 2021

DIFFERENT USES CASES OF try-catch in code

001. empty

catch (error) { }

002. showToast1

this.showToast('danger', 'Error', error.message || error);

003. showToast2

 } catch (error) {
    this.showToast('danger', error, 3000);
 }

004. return false

} catch (error) {
    return false;
}

005. setState1

} catch (err) {
    this.setState({
    error: `Data could not be fetched for ${this.props.fileName}`,
    currentFile: { file: this.props.fileName },
    });
}

006. setState2

} catch (error) {
  this.setState({error, isLoading: false})
}

007. setError

} catch (error) {
  setError(error);
}

008. getToasts().add

catch (err) {
    // We can't ensure the suggestions contains valid characters
    getToasts().add({
      color: 'danger',
      title: 'Error',
      text: 'The filter contains invalid characters',
      toastLifeTimeMs: 10000,
    });

009. Empty

}catch(error){

}

010. setError SetLoading

} catch (error) {
  setError(error);
  setLoading(false);
}

011. this.errorToast(err)

} catch (err) {
    this.setState({ isRefreshing: false });
    this.errorToast(err);
}

012.

} catch (e) {
    this.setState({ loadingReport: false });
}

013. console.log

} catch (err) {
  console.log(err);
}

014. onError(error)

}catch(error){
  onError && onError(error);
}

015. Promise.reject

} catch (error) {
  return Promise.reject(error);
}

014. this.handleError(error)

} catch (error) {
  this.handleError(error);
}

015. this.state.errors

} catch (error) {
    this.state.errors.push(`Error trying to create ${pattern} index pattern: ${error.message}`);
}

016. return { error }

} catch (err) {
    return {
        error: `Could not connect to API with id: ${hosts[i].id}: ${err.message || err}`,
    };
}

017. ErrorHandler.handle

} catch (error) {
  ErrorHandler.handle(error, 'Error loading agents');
}

018. getToasts().addDanger()

} catch (error) { 
    getToasts().addDanger({title: 'An error occurred while trying to get the most active agent', text: error.message || error });
}

019. this.apiOutputBox

} catch (error) {
    return this.apiOutputBox.setValue(
      'Wazuh API is not reachable. Reason: timeout.'
    );
}

020. console.warn

} catch (error) {
  console.warn(`Error when try to get cluster status`, error);
}

021. throw

} catch (error) {
  throw new Error(error);
}

022. this.props.updateError

} catch (error) {
  this.props.updateError(error);
}

023. getToasts().error

} catch (error) {
  getToasts().error('management:status:overview.fetchData', error);
}

@gabiwassan gabiwassan self-assigned this Jun 14, 2021
@frankeros frankeros removed the pending-PO Taks pending for PO validation and priorization label Jun 15, 2021
@pablomarga pablomarga self-assigned this Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants