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

Can I access an error that occurs inside subscribe? #428

Open
mikebridge opened this issue Jun 10, 2021 · 0 comments
Open

Can I access an error that occurs inside subscribe? #428

mikebridge opened this issue Jun 10, 2021 · 0 comments

Comments

@mikebridge
Copy link

mikebridge commented Jun 10, 2021

I have this:

const result = await csv()
    .fromFile(filePath)
    .subscribe(async (json, lineNumber) => {
	const saveResult = await saveToDb(json);
	if (!saveResult.isSuccessful) {
		log.error('throwing exception');
		log.error(saveResult.exception); // this shows the correct error message
		throw new Error(saveResult.exception);
	}
	return saveResult;
    }, (error) => {
	log.error('subscribe.error returning error');
	log.error(error); // this seems to be undefined??
	return error;
    }, () => {
	log.info('subscribe.completed');
    });

I expected the error handler to receive the thrown error saveResult.exception, but error is undefined.

If I throw the Error, it seems to cause the promise to terminate incorrectly. If I don't throw the error, the result is the json from the parsing, not the result of the subscription processing.

Is there a way to get the error message out of subscribe?

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