Skip to content

Commit 90c1a15

Browse files
etam-proEdward Tam
andauthored
PD-1516 - return 400 when request payload is invalid json (#18)
* PD-1516 - return 400 when request payload is invalid json * updated test fixtures --------- Co-authored-by: Edward Tam <edward.tam@flipp.com>
1 parent 313fcb3 commit 90c1a15

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

protoc-gen-rails/internal/output.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class {{.ControllerName}}Controller < ActionController::Base
6363
rescue_from GRPC::BadStatus do |e|
6464
render json: GrpcRest.error_msg(e), status: GrpcRest.grpc_http_status(e.code)
6565
end
66-
rescue_from Google::Protobuf::TypeError do |e|
66+
rescue_from ActionDispatch::Http::Parameters::ParseError, Google::Protobuf::TypeError do |e|
6767
render json: GrpcRest.error_msg(e), status: :bad_request
6868
end
6969
METHOD_PARAM_MAP = {
@@ -102,20 +102,22 @@ func ProcessService(service *descriptorpb.ServiceDescriptorProto, pkg string) (F
102102
return FileResult{}, routes, err
103103
}
104104
restOpts, err := ExtractRestOptions(m)
105-
if err != nil { return FileResult{}, routes, err }
105+
if err != nil {
106+
return FileResult{}, routes, err
107+
}
106108
httpMethod, path, err := MethodAndPath(opts.Pattern)
107109
pathInfo, err := ParsedPath(path)
108110
if err != nil {
109111
return FileResult{}, routes, err
110112
}
111113
controllerMethod := method{
112-
Name: strcase.ToSnake(m.GetName()),
113-
RequestType: Classify(m.GetInputType()),
114-
Path: path,
115-
RestOptions: rubyRestOptions(restOpts),
116-
HttpMethod: httpMethod,
117-
Body: opts.Body,
118-
PathInfo: pathInfo,
114+
Name: strcase.ToSnake(m.GetName()),
115+
RequestType: Classify(m.GetInputType()),
116+
Path: path,
117+
RestOptions: rubyRestOptions(restOpts),
118+
HttpMethod: httpMethod,
119+
Body: opts.Body,
120+
PathInfo: pathInfo,
119121
}
120122
data.Methods = append(data.Methods, controllerMethod)
121123
routes = append(routes, Route{

protoc-gen-rails/testdata/base/app/controllers/my_service_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ class MyServiceController < ActionController::Base
1111
rescue_from GRPC::BadStatus do |e|
1212
render json: GrpcRest.error_msg(e), status: GrpcRest.grpc_http_status(e.code)
1313
end
14-
rescue_from Google::Protobuf::TypeError do |e|
14+
rescue_from ActionDispatch::Http::Parameters::ParseError, Google::Protobuf::TypeError do |e|
1515
render json: GrpcRest.error_msg(e), status: :bad_request
1616
end
17+
1718
METHOD_PARAM_MAP = {
1819

1920
"test" => [

0 commit comments

Comments
 (0)