本文整理汇总了Golang中github.com/couchbase/query/errors.Error.Code方法的典型用法代码示例。如果您正苦于以下问题:Golang Error.Code方法的具体用法?Golang Error.Code怎么用?Golang Error.Code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/query/errors.Error
的用法示例。
在下文中一共展示了Error.Code方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Error
func (this *IndexConnection) Error(err errors.Error) {
if this.primary && err.Code() == errors.INDEX_SCAN_TIMEOUT {
this.timeout = true
return
}
this.context.Error(err)
}
示例2: mapErrorToHttpStatus
func mapErrorToHttpStatus(err errors.Error) int {
switch err.Code() {
case errors.ADMIN_AUTH_ERROR:
return http.StatusUnauthorized
case errors.ADMIN_SSL_NOT_ENABLED:
return http.StatusNotFound
default:
return http.StatusInternalServerError
}
}
示例3: mapErrorToHttpResponse
func mapErrorToHttpResponse(err errors.Error) int {
switch err.Code() {
case 1000: // readonly violation
return http.StatusForbidden
case 1010: // unsupported http method
return http.StatusMethodNotAllowed
case 1020, 1030, 1040, 1050, 1060, 1065, 1070:
return http.StatusBadRequest
case 1120:
return http.StatusNotAcceptable
case 3000: // parse error range
return http.StatusBadRequest
case 4000, errors.NO_SUCH_PREPARED: // plan error range
return http.StatusNotFound
case 5000:
return http.StatusInternalServerError
default:
return http.StatusInternalServerError
}
}
示例4: writeError
func (this *httpRequest) writeError(err errors.Error, count int) bool {
var rv bool
if count == 0 {
rv = this.writeString("\n")
} else {
rv = this.writeString(",\n")
}
m := map[string]interface{}{
"code": err.Code(),
"msg": err.Error(),
}
bytes, er := json.MarshalIndent(m, " ", " ")
if er != nil {
return false
}
return rv &&
this.writeString(" ") &&
this.writeString(string(bytes))
}
示例5: PrintError
/*
Function to print the error in Red.
*/
func PrintError(s_err errors.Error) {
tmpstr := fmt.Sprintln(fgRed, "ERROR", s_err.Code(), ":", s_err, reset)
io.WriteString(W, tmpstr+"\n")
}
示例6: newHttpRequest
func newHttpRequest(resp http.ResponseWriter, req *http.Request, bp BufferPool, size int) *httpRequest {
var httpArgs httpRequestArgs
var err errors.Error
// Limit body size in case of denial-of-service attack
req.Body = http.MaxBytesReader(resp, req.Body, int64(size))
e := req.ParseForm()
if e != nil {
err = errors.NewServiceErrorBadValue(e, "request form")
}
if err != nil && req.Method != "GET" && req.Method != "POST" {
err = errors.NewServiceErrorHTTPMethod(req.Method)
}
err = contentNegotiation(resp, req)
if err == nil {
httpArgs, err = getRequestParams(req)
}
var statement string
if err == nil {
statement, err = httpArgs.getStatement()
}
var prepared *plan.Prepared
if err == nil {
prepared, err = getPrepared(httpArgs)
plan, plan_err := getEncodedPlan(httpArgs)
if err != nil && err.Code() == errors.NO_SUCH_PREPARED {
if plan_err != nil {
err = plan_err
}
if plan_err == nil && plan != nil {
prepared = plan
err = nil
}
}
if err == nil && plan_err != nil {
err = plan_err
}
if prepared != nil && plan != nil && prepared.EncodedPlan() != plan.EncodedPlan() {
err = errors.NewPreparedEncodingMismatchError(prepared.Name())
}
}
if err == nil && statement == "" && prepared == nil {
err = errors.NewServiceErrorMissingValue("statement or prepared")
}
var namedArgs map[string]value.Value
if err == nil {
namedArgs, err = httpArgs.getNamedArgs()
}
var positionalArgs value.Values
if err == nil {
positionalArgs, err = httpArgs.getPositionalArgs()
}
var namespace string
if err == nil {
namespace, err = httpArgs.getString(NAMESPACE, "")
}
var timeout time.Duration
if err == nil {
timeout, err = httpArgs.getDuration(TIMEOUT)
}
var max_parallelism int
if err == nil {
var maxp string
maxp, err = httpArgs.getString(MAX_PARALLELISM, "")
if err == nil && maxp != "" {
var e error
max_parallelism, e = strconv.Atoi(maxp)
if e != nil {
err = errors.NewServiceErrorBadValue(e, "max parallelism")
}
}
}
var readonly value.Tristate
if err == nil {
readonly, err = getReadonly(httpArgs, req.Method == "GET")
}
var metrics value.Tristate
if err == nil {
metrics, err = httpArgs.getTristate(METRICS)
}
var format Format
if err == nil {
format, err = getFormat(httpArgs)
}
//.........这里部分代码省略.........