EventStore / EventStore-Client-NodeJS

A NodeJS client for Event Store
https://eventstore.com
Apache License 2.0
162 stars 22 forks source link

[BREAKING CHANGE] Update to grpc v1.9.0 #341

Closed George-Payne closed 1 year ago

George-Payne commented 1 year ago

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
    }
  }
}