Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(719)

Unified Diff: common/prpc/codes.go

Issue 1637193002: common/prpc, tools/cmd/cproto: prpc client (Closed) Base URL: https://github.com/luci/luci-go@prpc-server
Patch Set: Add some content length tests. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/prpc/client_test.go ('k') | common/prpc/generate.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/prpc/codes.go
diff --git a/common/prpc/codes.go b/common/prpc/codes.go
new file mode 100644
index 0000000000000000000000000000000000000000..1f1cf17b2718470b13bf189148fb10932b184b58
--- /dev/null
+++ b/common/prpc/codes.go
@@ -0,0 +1,48 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package prpc
+
+import (
+ "net/http"
+
+ "google.golang.org/grpc/codes"
+)
+
+// StatusCode maps HTTP statuses to gRPC codes.
+// Falls back to codes.Unknown.
+//
+// The behavior of this function may change when
+// https://github.com/grpc/grpc-common/issues/210
+// is closed.
+func StatusCode(status int) codes.Code {
+ switch {
+
+ case status >= 200 && status < 300:
+ return codes.OK
+
+ case status == http.StatusUnauthorized:
+ return codes.Unauthenticated
+ case status == http.StatusForbidden:
+ return codes.PermissionDenied
+ case status == http.StatusNotFound:
+ return codes.NotFound
+ case status == http.StatusGone:
+ return codes.NotFound
+ case status == http.StatusPreconditionFailed:
+ return codes.FailedPrecondition
+ case status >= 400 && status < 500:
+ return codes.InvalidArgument
+
+ case status == http.StatusNotImplemented:
+ return codes.Unimplemented
+ case status == http.StatusServiceUnavailable:
+ return codes.Unavailable
+ case status >= 500 && status < 600:
+ return codes.Internal
+
+ default:
+ return codes.Unknown
+ }
+}
« no previous file with comments | « common/prpc/client_test.go ('k') | common/prpc/generate.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698