Skip to content

Commit

Permalink
clean up and fix onError handling for client reset
Browse files Browse the repository at this point in the history
  • Loading branch information
RedBeard0531 committed Nov 23, 2022
1 parent f448e17 commit 800c41e
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions packages/realm/src/app-services/SyncSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,38 +115,25 @@ export function toBindingErrorHandlerWithOnManual(
throw new Error("need to set either onError or onManual or both");
}
if (onError && onManual) {
return (sessionInternal: binding.SyncSession, bindingError: binding.SyncError) => {
const session = new SyncSession(sessionInternal);
const error = fromBindingSyncError(bindingError);
return toBindingErrorHandler((session, error) => {
if (error instanceof ClientResetError) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
onManual(session, error.config.path!);
} else {
onError(session, error);
}
session.resetInternal();
};
});
}
if (onError) {
return (sessionInternal: binding.SyncSession, bindingError: binding.SyncError) => {
const session = new SyncSession(sessionInternal);
const error = fromBindingSyncError(bindingError);
if (error instanceof ClientResetError) {
onError(session, error);
}
session.resetInternal();
};
if (onError) { // onError gets all errors
return toBindingErrorHandler(onError);
}
if (onManual) {
return (sessionInternal: binding.SyncSession, bindingError: binding.SyncError) => {
const session = new SyncSession(sessionInternal);
const error = fromBindingSyncError(bindingError);
if (onManual) { // onManual only gets ClientResetErrors
return toBindingErrorHandler((session, error) => {
if (error instanceof ClientResetError) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
onManual(session, error.config.path!);
}
session.resetInternal();
};
});
}
}

Expand Down

0 comments on commit 800c41e

Please sign in to comment.