Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
acacd0d6
Commit
acacd0d6
authored
8 years ago
by
Alexander Polcyn
Browse files
Options
Downloads
Patches
Plain Diff
add factory method to bad status to create correct subclass
parent
6002b8ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ruby/lib/grpc/errors.rb
+43
-0
43 additions, 0 deletions
src/ruby/lib/grpc/errors.rb
src/ruby/spec/error_sanity_spec.rb
+7
-1
7 additions, 1 deletion
src/ruby/spec/error_sanity_spec.rb
with
50 additions
and
1 deletion
src/ruby/lib/grpc/errors.rb
+
43
−
0
View file @
acacd0d6
...
...
@@ -45,6 +45,8 @@ module GRPC
class
BadStatus
<
StandardError
attr_reader
:code
,
:details
,
:metadata
include
GRPC
::
Core
::
StatusCodes
# @param code [Numeric] the status code
# @param details [String] the details of the exception
# @param metadata [Hash] the error's metadata
...
...
@@ -62,6 +64,47 @@ module GRPC
def
to_status
Struct
::
Status
.
new
(
code
,
details
,
@metadata
)
end
def
self
.
new_status_exception
(
code
,
details
=
'unkown cause'
,
metadata
=
{})
case
code
when
OK
Ok
.
new
(
details
,
metadata
)
when
CANCELLED
Cancelled
.
new
(
details
,
metadata
)
when
UNKNOWN
Unknown
.
new
(
details
,
metadata
)
when
INVALID_ARGUMENT
InvalidArgument
.
new
(
details
,
metadata
)
when
DEADLINE_EXCEEDED
DeadlineExceeded
.
new
(
details
,
metadata
)
when
NOT_FOUND
NotFound
.
new
(
details
,
metadata
)
when
ALREADY_EXISTS
AlreadyExists
.
new
(
details
,
metadata
)
when
PERMISSION_DENIED
PermissionDenied
.
new
(
details
,
metadata
)
when
UNAUTHENTICATED
Unauthenticated
.
new
(
details
,
metadata
)
when
RESOURCE_EXHAUSTED
ResourceExhausted
.
new
(
details
,
metadata
)
when
FAILED_PRECONDITION
FailedPrecondition
.
new
(
details
,
metadata
)
when
ABORTED
Aborted
.
new
(
details
,
metadata
)
when
OUT_OF_RANGE
OutOfRange
.
new
(
details
,
metadata
)
when
UNIMPLEMENTED
Unimplemented
.
new
(
details
,
metadata
)
when
INTERNAL
Internal
.
new
(
details
,
metadata
)
when
UNAVAILABLE
Unavailable
.
new
(
details
,
metadata
)
when
DATA_LOSS
DataLoss
.
new
(
details
,
metadata
)
else
fail
'unknown code'
end
end
end
# GRPC status code corresponding to status OK
...
...
This diff is collapsed.
Click to expand it.
src/ruby/spec/error_sanity_spec.rb
+
7
−
1
View file @
acacd0d6
...
...
@@ -48,11 +48,17 @@ describe StatusCodes do
error_object
=
error_class
.
new
# check that the code matches the int value of the error's constant
expect
(
error_object
.
code
).
to
eq
(
StatusCodes
.
const_get
(
status_name
))
status_code
=
StatusCodes
.
const_get
(
status_name
)
expect
(
error_object
.
code
).
to
eq
(
status_code
)
# check default parameters
expect
(
error_object
.
details
).
to
eq
(
'unknown cause'
)
expect
(
error_object
.
metadata
).
to
eq
({})
# check that the BadStatus factory for creates the correct
# exception too
from_factory
=
GRPC
::
BadStatus
.
new_status_exception
(
status_code
)
expect
(
from_factory
.
is_a?
(
error_class
)).
to
be
(
true
)
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment