@@ -54,7 +54,33 @@ const (
5454 ErrUnavailableQuota int32 = 500101
5555)
5656
57- var errors = map [int32 ]string {}
57+ var errorsMap = map [int32 ]string {
58+ ErrInvalidParams : "Invalid parameter(s)" ,
59+ ErrUnhealthy : "Server is Unhealthy" ,
60+ ErrServiceAlreadyExists : "Micro-service already exists" ,
61+ ErrServiceNotExists : "Micro-service does not exist" ,
62+ ErrServiceVersionNotExists : "Micro-service version does not exist" ,
63+ ErrDeployedInstance : "Micro-service has deployed instance(s)" ,
64+ ErrDependedOnConsumer : "Consumer(s) depends on this micro-service" ,
65+ ErrUndefinedSchemaID : "Undefined schema id" ,
66+ ErrModifySchemaNotAllow : "Not allowed to modify schema" ,
67+ ErrSchemaNotExists : "Schema does not exist" ,
68+ ErrInstanceNotExists : "Instance does not exist" ,
69+ ErrPermissionDeny : "Access micro-service refused" ,
70+ ErrTagNotExists : "Tag does not exist" ,
71+ ErrRuleAlreadyExists : "Rule already exist" ,
72+ ErrBlackAndWhiteRule : "Can not have both 'BLACK' and 'WHITE'" ,
73+ ErrModifyRuleNotAllow : "Not allowed to modify the type of the rule" ,
74+ ErrRuleNotExists : "Rule does not exist" ,
75+ ErrNotEnoughQuota : "Not enough quota" ,
76+ ErrUnauthorized : "Request unauthorized" ,
77+ ErrInternal : "Internal server error" ,
78+ ErrUnavailableBackend : "Registry service is unavailable" ,
79+ ErrUnavailableQuota : "Quota service is unavailable" ,
80+ ErrEndpointAlreadyExists : "Endpoint is already belong to other service" ,
81+ ErrForbidden : "Forbidden" ,
82+ ErrConflictAccount : "account name is duplicated" ,
83+ }
5884
5985type Error struct {
6086 Code int32 `json:"errorCode,string"`
@@ -85,11 +111,20 @@ func (e *Error) InternalError() bool {
85111func NewError (code int32 , detail string ) * Error {
86112 return & Error {
87113 Code : code ,
88- Message : errors [code ],
114+ Message : errorsMap [code ],
89115 Detail : detail ,
90116 }
91117}
92118
93119func NewErrorf (code int32 , format string , args ... interface {}) * Error {
94120 return NewError (code , fmt .Sprintf (format , args ... ))
95121}
122+ func RegisterErrors (errs map [int32 ]string ) {
123+ for err , msg := range errs {
124+ if err < 400000 || err >= 600000 {
125+ fmt .Sprintf ("error code[%v] should be between 4xx and 5xx\n " , err )
126+ continue
127+ }
128+ errorsMap [err ] = msg
129+ }
130+ }
0 commit comments