Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
Better ingress error message on permission denied
Browse files Browse the repository at this point in the history
  • Loading branch information
cathyzhyi committed Sep 3, 2020
1 parent 57e63f9 commit 8203b84
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/broker/ingress/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"time"

cev2 "github.com/cloudevents/sdk-go/v2"
grpcstatus "google.golang.org/grpc/status"
grpccode "google.golang.org/grpc/codes"
"github.com/cloudevents/sdk-go/v2/binding"
"github.com/cloudevents/sdk-go/v2/binding/transformer"
ceclient "github.com/cloudevents/sdk-go/v2/client"
Expand Down Expand Up @@ -158,10 +160,18 @@ func (h *Handler) ServeHTTP(response nethttp.ResponseWriter, request *nethttp.Re
if res := h.decouple.Send(ctx, broker, *event); !cev2.IsACK(res) {
h.logger.Error("Error publishing to PubSub", zap.String("broker", broker.String()), zap.Error(res))
statusCode = nethttp.StatusInternalServerError
if errors.Is(res, ErrNotFound) {

switch {
case errors.Is(res, ErrNotFound):
statusCode = nethttp.StatusNotFound
} else if errors.Is(res, ErrNotReady) {
case errors.Is(res, ErrNotReady):
statusCode = nethttp.StatusServiceUnavailable
case grpcstatus.Code(res) == grpccode.PermissionDenied:
const msg string = "Failed to publish to PubSub because permission denied.\n" +
"Please refer to \"Configure the Authentication Mechanism for GCP\" at " +
"https://github.com/google/knative-gcp/blob/master/docs/install/install-gcp-broker.md"
nethttp.Error(response, msg, statusCode)
return
}
nethttp.Error(response, "Failed to publish to PubSub", statusCode)
return
Expand Down

0 comments on commit 8203b84

Please sign in to comment.