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

No way to recover if ObservableCollection#insert() fails synchronously #248

Open
domq opened this issue Nov 19, 2019 · 1 comment
Open

Comments

@domq
Copy link

domq commented Nov 19, 2019

In the case where ObservableCollection#insert fails synchronously (e.g. when attempting to insert into a collection that has a simpl-schema), the following code should catch the error:

collection.insert({}).pipe(catchError(error => {
    console.error(error)
    return []
}))

Unfortunately it doesn't, because the error will have run its course even before .insert() returns and the .pipe() has a chance to be fitted.

@domq
Copy link
Author

domq commented Nov 19, 2019

A workaround is to not use ObservableCollection#insert and use a plain old callback on the plain old Mongo.Collection object, i.e.

collection.collection.insert({}, (error: any, id: any) => {
    if (error) {
        console.error(error)
    } else {
        console.log(id)
    }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant