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 2, 2020
1 parent 57e63f9 commit 244d3c1
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-knative-gcp.md"
nethttp.Error(response, msg, statusCode)
return
}
nethttp.Error(response, "Failed to publish to PubSub", statusCode)
return
Expand Down

0 comments on commit 244d3c1

Please sign in to comment.