[Refactor] Impose definite error handling mechanism in Client Classes #904
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)