Handle Payload errors with instanceof operator #13555
Replies: 1 comment
-
Ok, so few findings after more testing - code is still the same piece from my original post (so the fragment with I put two comparisons in catch, one after each other:
Dev server (
Production server (
In payload repo, result from production server also occurs (for example in So this doesn't quite look like microsoft/TypeScript#13965. I still don't quite understand why this doesn't happen on dev server, but maybe it reads everything from source which results in just one I wonder whether placing errors in separate package could help? Currently they are a part of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
In reference to short Discord discussion (https://discord.com/channels/967097582721572934/967097582721572937/1408477234347511909), I'm creating a discussion here.
The problem is related to error classes from
payload
package. Currently, when handling errors, it is not possible to detect which error is it using well-knowninstanceof
operator. While it may look like this is working initially, after building the app information about error class are lost, no matter if Next config'sserverMinification
option is disabled or not.Apparently this is a known issue, but in my opinion it not only significantly affects DX, but can lead to unexpected behavior - especially since this issue stays dormant, unless you build the app and test selected code path here. I've discovered it myself only after tests I've written were not passing on production build for because of not matching expected error messages.
Sample of broken code:
Currently my workaround looks like this:
While not super-clean, it at least mimics how this would be handled if this bug wasn't here. Also, a codemod will be easy to create after root cause is resolved. One caveat is that it requires
serverMinification
option to be disabled, because otherwise class names will be lost during build.I've tried to find out what could be the problem, but I haven't reached any definitive conclusion. I found some similar issues, but they don't match what we have here 100%:
Beta Was this translation helpful? Give feedback.
All reactions