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

Unified Diff: server/prpc/error.go

Issue 1605363002: common/prpc, tools/cmd/cproto: prpc client (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: rebased and addressed comments 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 | « server/prpc/encoding_test.go ('k') | server/prpc/error_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/prpc/error.go
diff --git a/server/prpc/error.go b/server/prpc/error.go
index 950ef99f65c3787f36c451cf1653057d8e3c54a7..1795fa12ecfbff00c7f03b989d350c2b30ef454a 100644
--- a/server/prpc/error.go
+++ b/server/prpc/error.go
@@ -4,45 +4,33 @@
package prpc
-import "fmt"
+import (
+ "fmt"
+)
-// httpError is an error with HTTP status.
-// Many internal functions return *httpError instead of error
-// to guarantee expected HTTP status via type-system.
-// Supported by ErrorStatus and ErrorDesc.
-type httpError struct {
+// protocolError is returned if a pRPC request is malformed.
+type protocolError struct {
err error
- status int
+ status int // HTTP status to use in response.
}
-func (e *httpError) Error() string {
- return fmt.Sprintf("HTTP %d: %s", e.status, e.err)
+func (e *protocolError) Error() string {
+ return fmt.Sprintf("pRPC: %s", e.err)
}
// withStatus wraps an error with an HTTP status.
// If err is nil, returns nil.
-func withStatus(err error, status int) *httpError {
- if _, ok := err.(*httpError); ok {
- panicf("httpError in httpError")
+func withStatus(err error, status int) *protocolError {
+ if _, ok := err.(*protocolError); ok {
+ panic("protocolError in protocolError")
}
if err == nil {
return nil
}
- return &httpError{err, status}
+ return &protocolError{err, status}
}
-// errorf creates a new error with an HTTP status.
-func errorf(status int, format string, a ...interface{}) *httpError {
+// errorf creates a new protocol error.
+func errorf(status int, format string, a ...interface{}) *protocolError {
return withStatus(fmt.Errorf(format, a...), status)
}
-
-// Errorf creates a new error with an HTTP status.
-//
-// See also grpc.Errorf that accepts a gRPC code.
-func Errorf(status int, format string, a ...interface{}) error {
- return errorf(status, format, a...)
-}
-
-func panicf(format string, a ...interface{}) {
- panic(fmt.Errorf(format, a...))
-}
« no previous file with comments | « server/prpc/encoding_test.go ('k') | server/prpc/error_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698