當前位置: 首頁>>代碼示例>>Golang>>正文


Golang errors.Error類代碼示例

本文整理匯總了Golang中github.com/couchbase/query/errors.Error的典型用法代碼示例。如果您正苦於以下問題:Golang Error類的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Error類的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)
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:7,代碼來源:index.go

示例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
	}
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:10,代碼來源:admin_endpoint.go

示例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
	}
}
開發者ID:jmptrader,項目名稱:query,代碼行數:20,代碼來源:service_response.go

示例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))
}
開發者ID:jmptrader,項目名稱:query,代碼行數:21,代碼來源:service_response.go

示例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")
}
開發者ID:couchbaselabs,項目名稱:go_cbq,代碼行數:7,代碼來源:error.go

示例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)
	}
//.........這裏部分代碼省略.........
開發者ID:pkdevboxy,項目名稱:query,代碼行數:101,代碼來源:service_request.go


注:本文中的github.com/couchbase/query/errors.Error類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。