grpc-rest 0.1.13 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -1
- data/Gemfile.lock +1 -1
- data/lib/grpc_rest/version.rb +1 -1
- data/lib/grpc_rest.rb +47 -2
- data/protoc-gen-rails/internal/output.go +7 -1
- data/protoc-gen-rails/testdata/base/app/controllers/my_service_controller.rb +7 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61c130f717134177cf54979446039f2be1144a66f1fb8e0eb85b64f4bdf70bcc
|
4
|
+
data.tar.gz: bf5fdf842d2f8c1aa20e45fdd88eff0f0d7cabeb8decf77c9bcb6ae7e3794a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 006c5943b3bc2b497fcc591527c3d14558a0a6f54922baca7d8d445248ded8718c3debb406440411c48cf869061a28dbd5b3e2135c6aee1a168dd5b149e7ee43
|
7
|
+
data.tar.gz: e667e1f72ae7ba6cfea978e9e075f4758e101bfd9b8c3b07b5c4f0110d7c51b18bc1304baf923da5279a7b8d9b6a18e69e44c8918b71e746e0d8557b47095eaf
|
data/CHANGELOG
CHANGED
@@ -7,8 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
+
# 0.1.15 - 2024-06-26
|
11
|
+
- Actually emit the correct error code on failure. :(
|
12
|
+
|
13
|
+
# 0.1.14 - 2024-06-25
|
14
|
+
- Emit the correct error code on failure.
|
15
|
+
|
10
16
|
# 0.1.13 - 2024-06-24
|
11
|
-
- Use
|
17
|
+
- Use grpc's `to_json` methods to output fields correctly.
|
12
18
|
|
13
19
|
# 0.1.12 - 2024-05-15
|
14
20
|
- Parse numbers into Ruby number objects.
|
data/Gemfile.lock
CHANGED
data/lib/grpc_rest/version.rb
CHANGED
data/lib/grpc_rest.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'google/protobuf/well_known_types'
|
2
2
|
require 'grpc'
|
3
|
+
require 'grpc/core/status_codes'
|
3
4
|
|
4
5
|
module GrpcRest
|
5
6
|
class << self
|
@@ -105,16 +106,60 @@ module GrpcRest
|
|
105
106
|
end
|
106
107
|
end
|
107
108
|
|
109
|
+
# Ported from https://github.com/grpc-ecosystem/grpc-gateway/blob/main/runtime/errors.go#L36
|
110
|
+
def grpc_http_status(code)
|
111
|
+
case code
|
112
|
+
when GRPC::Core::StatusCodes::OK
|
113
|
+
:ok
|
114
|
+
when GRPC::Core::StatusCodes::CANCELLED
|
115
|
+
499
|
116
|
+
when GRPC::Core::StatusCodes::INVALID_ARGUMENT,
|
117
|
+
GRPC::Core::StatusCodes::FAILED_PRECONDITION,
|
118
|
+
GRPC::Core::StatusCodes::OUT_OF_RANGE
|
119
|
+
:bad_request
|
120
|
+
when GRPC::Core::StatusCodes::DEADLINE_EXCEEDED
|
121
|
+
:gateway_timeout
|
122
|
+
when GRPC::Core::StatusCodes::NOT_FOUND
|
123
|
+
:not_found
|
124
|
+
when GRPC::Core::StatusCodes::ALREADY_EXISTS, GRPC::Core::StatusCodes::ABORTED
|
125
|
+
:conflict
|
126
|
+
when GRPC::Core::StatusCodes::PERMISSION_DENIED
|
127
|
+
:forbidden
|
128
|
+
when GRPC::Core::StatusCodes::UNAUTHENTICATED
|
129
|
+
:unauthorized
|
130
|
+
when GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED
|
131
|
+
:too_many_requests
|
132
|
+
when GRPC::Core::StatusCodes::UNIMPLEMENTED
|
133
|
+
:not_implemented
|
134
|
+
when GRPC::Core::StatusCodes::UNAVAILABLE
|
135
|
+
:service_unavailable
|
136
|
+
else
|
137
|
+
:internal_server_error
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
108
141
|
def error_msg(error)
|
142
|
+
if error.respond_to?(:code)
|
109
143
|
{
|
110
|
-
code:
|
111
|
-
message:
|
144
|
+
code: error.code,
|
145
|
+
message: error.message,
|
112
146
|
details: [
|
113
147
|
{
|
114
148
|
backtrace: error.backtrace
|
115
149
|
}
|
116
150
|
]
|
117
151
|
}
|
152
|
+
else
|
153
|
+
{
|
154
|
+
code: 3,
|
155
|
+
message: "InvalidArgument: #{error.message}",
|
156
|
+
details: [
|
157
|
+
{
|
158
|
+
backtrace: error.backtrace
|
159
|
+
}
|
160
|
+
]
|
161
|
+
}
|
162
|
+
end
|
118
163
|
end
|
119
164
|
|
120
165
|
def send_gruf_request(klass, service_obj, method, request)
|
@@ -46,8 +46,14 @@ class {{.ControllerName}}Controller < ActionController::Base
|
|
46
46
|
protect_from_forgery with: :null_session
|
47
47
|
|
48
48
|
rescue_from StandardError do |e|
|
49
|
-
render json: GrpcRest.error_msg(e)
|
49
|
+
render json: GrpcRest.error_msg(e), status: :internal_server_error
|
50
50
|
end
|
51
|
+
rescue_from GRPC::BadStatus do |e|
|
52
|
+
render json: GrpcRest.error_msg(e), status: GrpcRest.grpc_http_status(e.code)
|
53
|
+
end
|
54
|
+
rescue_from Google::Protobuf::TypeError do |e|
|
55
|
+
render json: GrpcRest.error_msg(e), status: :bad_request
|
56
|
+
end
|
51
57
|
METHOD_PARAM_MAP = {
|
52
58
|
{{range .Methods }}
|
53
59
|
"{{.Name}}" => [
|
@@ -6,8 +6,14 @@ class MyServiceController < ActionController::Base
|
|
6
6
|
protect_from_forgery with: :null_session
|
7
7
|
|
8
8
|
rescue_from StandardError do |e|
|
9
|
-
render json: GrpcRest.error_msg(e)
|
9
|
+
render json: GrpcRest.error_msg(e), status: :internal_server_error
|
10
10
|
end
|
11
|
+
rescue_from GRPC::BadStatus do |e|
|
12
|
+
render json: GrpcRest.error_msg(e), status: GrpcRest.grpc_http_status(e.code)
|
13
|
+
end
|
14
|
+
rescue_from Google::Protobuf::TypeError do |e|
|
15
|
+
render json: GrpcRest.error_msg(e), status: :bad_request
|
16
|
+
end
|
11
17
|
METHOD_PARAM_MAP = {
|
12
18
|
|
13
19
|
"test" => [
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grpc-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|