Exception: Gcloud::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Gcloud::Error
- Defined in:
- lib/gcloud/errors.rb
Overview
Base gcloud-ruby exception class.
Direct Known Subclasses
AbortedError, AlreadyExistsError, CanceledError, DataLossError, Datastore::KeyError, Datastore::PropertyError, Datastore::TransactionError, DeadlineExceededError, FailedPreconditionError, InternalError, InvalidArgumentError, NotFoundError, OutOfRangeError, PermissionDeniedError, ResourceExhaustedError, Storage::FileVerificationError, Storage::SignedUrlUnavailable, UnauthenticatedError, UnavailableError, UnimplementedError, UnknownError
Class Method Summary collapse
- .from_error(error) ⇒ Object
- .gapi_error_class_for(http_status_code) ⇒ Object
- .grpc_error_class_for(grpc_error_code) ⇒ Object
Class Method Details
.from_error(error) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gcloud/errors.rb', line 21 def self.from_error error klass = if error.respond_to? :code grpc_error_class_for error.code elsif error.respond_to? :status_code gapi_error_class_for error.status_code else self end klass.new error. end |
.gapi_error_class_for(http_status_code) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gcloud/errors.rb', line 45 def self.gapi_error_class_for http_status_code # The http status codes mapped to their error classes. { 400 => InvalidArgumentError, # FailedPreconditionError/OutOfRangeError 401 => UnauthenticatedError, 403 => PermissionDeniedError, 404 => NotFoundError, 409 => AlreadyExistsError, # AbortedError 429 => ResourceExhaustedError, 499 => CanceledError, 500 => InternalError, # UnknownError/DataLossError 501 => UnimplementedError, 503 => UnavailableError, 504 => DeadlineExceededError }[http_status_code] || self end |
.grpc_error_class_for(grpc_error_code) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gcloud/errors.rb', line 33 def self.grpc_error_class_for grpc_error_code # The gRPC status code 0 is for a successful response. # So there is no error subclass for a 0 status code, use current class. [self, CanceledError, UnknownError, InvalidArgumentError, DeadlineExceededError, NotFoundError, AlreadyExistsError, PermissionDeniedError, ResourceExhaustedError, FailedPreconditionError, AbortedError, OutOfRangeError, UnimplementedError, InternalError, UnavailableError, DataLossError, UnauthenticatedError ][grpc_error_code] || self end |