I think we need to define the errors we raise with consistent error codes. This will enable the front end to display the correct UI to the user depending on the type of error.
Some errors will be expected, e.g.
Blob or Record not found
Peer disconnects
The simple way to do this is with instance checks e.g.
class ErrNotFound extends Error {
constructor(message) {
super(message)
}
}
if (err instanceof ErrNotFound) {
//...
}
However this doesn't work over RPC. I recommend defining error codes, then each error should have a .code property. rpc-reflector uses serialize-error to serialize errors over RPC, so it will preserve error.code properties.
I was just looking through the Node code for how they define errors, which seems like a good start. I would have thought there would be a neat library on npm to define errors, but it's a hard thing to find the right search terms.
I think we need to define the errors we raise with consistent error codes. This will enable the front end to display the correct UI to the user depending on the type of error.
Some errors will be expected, e.g.
The simple way to do this is with instance checks e.g.
However this doesn't work over RPC. I recommend defining error codes, then each error should have a
.code
property.rpc-reflector
usesserialize-error
to serialize errors over RPC, so it will preserveerror.code
properties.I was just looking through the Node code for how they define errors, which seems like a good start. I would have thought there would be a neat library on npm to define errors, but it's a hard thing to find the right search terms.