Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

[Refactor] Impose definite error handling mechanism in Client Classes #904

Open
@rohithbalaji123

Description

What is frustrating you?
The catch block of most Promises have multiple predicates and the errors are handled in different ways in different services.
For eg: The lines here and here handle the error in the service layer and splits it into AuthenticationErr and <Custom>Err which is then handled in the component level on what to do with them whereas, here, we return the error code which is to be handled in React components layer.

Your solution
We should come up with a strict Error Handling mechanism. This could involve extending native error types and adding multiple catch blocks for our usecases.

try {
    changeLogsService.createChange(change);
} catch (e if e instanceof AuthenticationError) {
    redirectToLogin();
} catch (e) {
    raiseCreateChangeError(e);
}

Alternatives considered
We could continue what we are already doing with respect to how the errors are handled in components. That is.,

try {
    changeLogsService.createChange(change);
} catch ({ authenticationErr, createChangeErr }) {
    if (authenticationErr) {
        redirectToLogin();
        return;
    }
    raiseCreateChangeError(e);
}

But, we should maintain consistency on what is returned to each layers(React Components, Services and GraphQLAPIs)

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions