• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang errors.Error类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang expression.NewFormalizer函数代码示例发布时间:2022-05-23
下一篇:
Golang errors.NewSystemNotImplementedError函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap