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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « common/prpc/client_test.go ('k') | common/prpc/generate.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package prpc
6
7 import (
8 "net/http"
9
10 "google.golang.org/grpc/codes"
11 )
12
13 // StatusCode maps HTTP statuses to gRPC codes.
14 // Falls back to codes.Unknown.
15 //
16 // The behavior of this function may change when
17 // https://github.com/grpc/grpc-common/issues/210
18 // is closed.
19 func StatusCode(status int) codes.Code {
20 switch {
21
22 case status >= 200 && status < 300:
23 return codes.OK
24
25 case status == http.StatusUnauthorized:
26 return codes.Unauthenticated
27 case status == http.StatusForbidden:
28 return codes.PermissionDenied
29 case status == http.StatusNotFound:
30 return codes.NotFound
31 case status == http.StatusGone:
32 return codes.NotFound
33 case status == http.StatusPreconditionFailed:
34 return codes.FailedPrecondition
35 case status >= 400 && status < 500:
36 return codes.InvalidArgument
37
38 case status == http.StatusNotImplemented:
39 return codes.Unimplemented
40 case status == http.StatusServiceUnavailable:
41 return codes.Unavailable
42 case status >= 500 && status < 600:
43 return codes.Internal
44
45 default:
46 return codes.Unknown
47 }
48 }
OLDNEW
« 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