In the old version of "prismic-javascript": "^3.0.2" I would get an 'undefined' and move on, but in the latest version everything is breaking because of the error.
Am I doing something wrong or is this the expected behaviour?
Welcome to the Prismic community, and thanks for reaching out to us.
I have experienced this issue, too, and I agree that it should return an empty object or undefined. I'll bring this up with my dedicated team. For the moment, you have to do error handling by applying try.. catch block.
I don't have an ETA at the moment and I believe it's not in their roadmap because:
Querying by UID using a non-existing UID yields a PrismicError, this is intended;
Querying by UID using a non-existing document type yields a ParsingError, this is intended as the document type doesn't exist in the queried Prismic repository.
You need to put a try-catch block to catch errors like this:
I am just starting development with prismic client and this behaviour is really weird.
I guess the fact that you are returning an error is not a massive problem. But the fact that you are returning PrismicError instead of NotFoundError is at least problematic.
For example, in your example provided ParsingError is actually PrismicError too. So if we try to catch PrismicErrors we will catch a bunch of stuff that we shouldn't catch.
The only solution then is actually doing something like that if I don't want to have my logs completely overrun:
Welcome to the Prismic community, and thanks for reaching out to us.
That was a workaround. And as I mentioned before, I have already created an issue in Prismic issue tracker. But I don't have any ETA for the moment to get fix.