MIGRATING.md in google-cloud-speech-1.1.0 vs MIGRATING.md in google-cloud-speech-1.1.1

- old
+ new

@@ -28,10 +28,14 @@ * Previously, the client included a method supporting bidirectional streaming recognition requests, both incremental audio and incremental results. The current client retains this method, but simplifies the interface to match streaming methods in other Ruby clients. See [Streaming Interface](#streaming-interface) for more info. + * Previously, clients reported RPC errors by raising instances of + `Google::Gax::GaxError` and its subclasses. Now, RPC exceptions are of type + `Google::Cloud::Error` and its subclasses. See + [Handling Errors](#handling-errors) for more info. * Some classes have moved into different namespaces. See [Class Namespaces](#class-namespaces) for more info. ### Library Structure @@ -283,9 +287,65 @@ input_stream.push({ audio_content: File.read("my_input.flac", mode: "rb") }) input_stream.close output_stream.each do |response| puts "received: #{response}" +end +``` + +### Handling Errors + +The client reports standard +[gRPC error codes](https://github.com/grpc/grpc/blob/master/doc/statuscodes.md) +by raising exceptions. In older releases, these exceptions were located in the +`Google::Gax` namespace and were subclasses of the `Google::Gax::GaxError` base +exception class, defined in the `google-gax` gem. However, these classes were +different from the standard exceptions (subclasses of `Google::Cloud::Error`) +thrown by other client libraries such as `google-cloud-storage`. + +The 1.0 client library now uses the `Google::Cloud::Error` exception hierarchy, +for consistency across all the Google Cloud client libraries. In general, these +exceptions have the same name as their counterparts from older releases, but +are located in the `Google::Cloud` namespace rather than the `Google::Gax` +namespace. + +Old: +``` +client = Google::Cloud::Speech.new + +config = { + language_code: "en-US", + sample_rate_hertz: 44_100, + encoding: :FLAC +} +audio = { + uri: "gs://cloud-samples-data/speech/brooklyn_bridge.flac" +} + +begin + response = client.recognize config, audio +rescue Google::Gax::Error => e + # Handle exceptions that subclass Google::Gax::Error +end +``` + +New: +``` +client = Google::Cloud::Speech.speech + +config = { + language_code: "en-US", + sample_rate_hertz: 44_100, + encoding: :FLAC +} +audio = { + uri: "gs://cloud-samples-data/speech/brooklyn_bridge.flac" +} + +begin + response = client.recognize config: config, audio: audio +rescue Google::Cloud::Error => e + # Handle exceptions that subclass Google::Cloud::Error end ``` ### Class Namespaces