Skip to content

Commit

Permalink
PD-1516 - return 400 when request payload is invalid json
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Tam committed Nov 24, 2024
1 parent 313fcb3 commit 6df46b1
Showing 1 changed file with 11 additions and 9 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

0 comments on commit 6df46b1

Please sign in to comment.