Skip to content

Commit

Permalink
PD-1516 - return 400 when request payload is invalid json (#18)
Browse files Browse the repository at this point in the history
* PD-1516 - return 400 when request payload is invalid json

* updated test fixtures

---------

Co-authored-by: Edward Tam <[email protected]>
  • Loading branch information
etam-pro and Edward Tam authored Nov 25, 2024
1 parent 313fcb3 commit 90c1a15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions protoc-gen-rails/internal/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class {{.ControllerName}}Controller < ActionController::Base
rescue_from GRPC::BadStatus do |e|
render json: GrpcRest.error_msg(e), status: GrpcRest.grpc_http_status(e.code)
end
rescue_from Google::Protobuf::TypeError do |e|
rescue_from ActionDispatch::Http::Parameters::ParseError, Google::Protobuf::TypeError do |e|
render json: GrpcRest.error_msg(e), status: :bad_request
end
METHOD_PARAM_MAP = {
Expand Down Expand Up @@ -102,20 +102,22 @@ func ProcessService(service *descriptorpb.ServiceDescriptorProto, pkg string) (F
return FileResult{}, routes, err
}
restOpts, err := ExtractRestOptions(m)
if err != nil { return FileResult{}, routes, err }
if err != nil {
return FileResult{}, routes, err
}
httpMethod, path, err := MethodAndPath(opts.Pattern)
pathInfo, err := ParsedPath(path)
if err != nil {
return FileResult{}, routes, err
}
controllerMethod := method{
Name: strcase.ToSnake(m.GetName()),
RequestType: Classify(m.GetInputType()),
Path: path,
RestOptions: rubyRestOptions(restOpts),
HttpMethod: httpMethod,
Body: opts.Body,
PathInfo: pathInfo,
Name: strcase.ToSnake(m.GetName()),
RequestType: Classify(m.GetInputType()),
Path: path,
RestOptions: rubyRestOptions(restOpts),
HttpMethod: httpMethod,
Body: opts.Body,
PathInfo: pathInfo,
}
data.Methods = append(data.Methods, controllerMethod)
routes = append(routes, Route{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class MyServiceController < ActionController::Base
rescue_from GRPC::BadStatus do |e|
render json: GrpcRest.error_msg(e), status: GrpcRest.grpc_http_status(e.code)
end
rescue_from Google::Protobuf::TypeError do |e|
rescue_from ActionDispatch::Http::Parameters::ParseError, Google::Protobuf::TypeError do |e|
render json: GrpcRest.error_msg(e), status: :bad_request
end

METHOD_PARAM_MAP = {

"test" => [
Expand Down

0 comments on commit 90c1a15

Please sign in to comment.