mirror of
https://github.com/go-gitea/gitea
synced 2024-09-19 02:06:04 +00:00
b6a95a8cb3
* Dropped unused codekit config * Integrated dynamic and static bindata for public * Ignore public bindata * Add a general generate make task * Integrated flexible public assets into web command * Updated vendoring, added all missiong govendor deps * Made the linter happy with the bindata and dynamic code * Moved public bindata definition to modules directory * Ignoring the new bindata path now * Updated to the new public modules import path * Updated public bindata command and drop the new prefix
50 lines
935 B
Go
50 lines
935 B
Go
package etcd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
ErrCodeEtcdNotReachable = 501
|
|
ErrCodeUnhandledHTTPStatus = 502
|
|
)
|
|
|
|
var (
|
|
errorMap = map[int]string{
|
|
ErrCodeEtcdNotReachable: "All the given peers are not reachable",
|
|
}
|
|
)
|
|
|
|
type EtcdError struct {
|
|
ErrorCode int `json:"errorCode"`
|
|
Message string `json:"message"`
|
|
Cause string `json:"cause,omitempty"`
|
|
Index uint64 `json:"index"`
|
|
}
|
|
|
|
func (e EtcdError) Error() string {
|
|
return fmt.Sprintf("%v: %v (%v) [%v]", e.ErrorCode, e.Message, e.Cause, e.Index)
|
|
}
|
|
|
|
func newError(errorCode int, cause string, index uint64) *EtcdError {
|
|
return &EtcdError{
|
|
ErrorCode: errorCode,
|
|
Message: errorMap[errorCode],
|
|
Cause: cause,
|
|
Index: index,
|
|
}
|
|
}
|
|
|
|
func handleError(b []byte) error {
|
|
etcdErr := new(EtcdError)
|
|
|
|
err := json.Unmarshal(b, etcdErr)
|
|
if err != nil {
|
|
logger.Warningf("cannot unmarshal etcd error: %v", err)
|
|
return err
|
|
}
|
|
|
|
return etcdErr
|
|
}
|