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 opened this issue Jun 28, 2020 · 0 comments

Comments

@rohithbalaji123
Copy link
Member

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)

@rohithbalaji123 rohithbalaji123 changed the title [Refactor] [Refactor] Impose definite error handling mechanism in Client Services and APIs Jun 28, 2020
@rohithbalaji123 rohithbalaji123 changed the title [Refactor] Impose definite error handling mechanism in Client Services and APIs [Refactor] Impose definite error handling mechanism in Client Classes Jun 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant