Update error handling to correctly handle CANCELLED
GRPCjs now throws a CANCELLED error when a stream is cancelled by the server, where previously it would throw a UNAVAILABLE status.
We now handle this error internally in the same way as an UNAVAILABLE error, but throw a CancelledError.
If users are catching UnavailableError on a stream for this situation, they should now be looking for a CancelledError.
Before:
try {
for await (const event of client.readStream("my_stream")) {
// do something
}
} catch (error) {
if (isCommandError(error)) {
if (error.type === ErrorType.UNAVAILABLE) {
// Server is unavailable to take request
// _OR_
// Stream was cancelled by server
}
}
}
After:
try {
for await (const event of client.readStream("my_stream")) {
// do something
}
} catch (error) {
if (isCommandError(error)) {
if (error.type === ErrorType.CANCELLED) {
// Stream was cancelled by server
}
if (error.type === ErrorType.UNAVAILABLE) {
// Server is unavailable to take request
}
}
}
CANCELLED
GRPCjs now throws a
CANCELLED
error when a stream is cancelled by the server, where previously it would throw aUNAVAILABLE
status. We now handle this error internally in the same way as anUNAVAILABLE
error, but throw aCancelledError
. If users are catchingUnavailableError
on a stream for this situation, they should now be looking for aCancelledError
.Before:
After: