123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package internal
- import (
- "fmt"
- "github.com/golang/protobuf/proto"
- remotepb "google.golang.org/appengine/internal/remote_api"
- )
- var errorCodeMaps = make(map[string]map[int32]string)
- func RegisterErrorCodeMap(service string, m map[int32]string) {
- errorCodeMaps[service] = m
- }
- type timeoutCodeKey struct {
- service string
- code int32
- }
- var timeoutCodes = make(map[timeoutCodeKey]bool)
- func RegisterTimeoutErrorCode(service string, code int32) {
- timeoutCodes[timeoutCodeKey{service, code}] = true
- }
- type APIError struct {
- Service string
- Detail string
- Code int32
- }
- func (e *APIError) Error() string {
- if e.Code == 0 {
- if e.Detail == "" {
- return "APIError <empty>"
- }
- return e.Detail
- }
- s := fmt.Sprintf("API error %d", e.Code)
- if m, ok := errorCodeMaps[e.Service]; ok {
- s += " (" + e.Service + ": " + m[e.Code] + ")"
- } else {
-
- s = e.Service + " " + s
- }
- if e.Detail != "" {
- s += ": " + e.Detail
- }
- return s
- }
- func (e *APIError) IsTimeout() bool {
- return timeoutCodes[timeoutCodeKey{e.Service, e.Code}]
- }
- type CallError struct {
- Detail string
- Code int32
-
- Timeout bool
- }
- func (e *CallError) Error() string {
- var msg string
- switch remotepb.RpcError_ErrorCode(e.Code) {
- case remotepb.RpcError_UNKNOWN:
- return e.Detail
- case remotepb.RpcError_OVER_QUOTA:
- msg = "Over quota"
- case remotepb.RpcError_CAPABILITY_DISABLED:
- msg = "Capability disabled"
- case remotepb.RpcError_CANCELLED:
- msg = "Canceled"
- default:
- msg = fmt.Sprintf("Call error %d", e.Code)
- }
- s := msg + ": " + e.Detail
- if e.Timeout {
- s += " (timeout)"
- }
- return s
- }
- func (e *CallError) IsTimeout() bool {
- return e.Timeout
- }
- var NamespaceMods = make(map[string]func(m proto.Message, namespace string))
|