// AdjustErrorStatusCode adjusts the status that will be sent in error
// conditions in a way that can be shared across http's respondError and other
// locations.
160412
func AdjustErrorStatusCode(status *int, err error) {
	// Handle nested errors
	if t, ok := err.(*multierror.Error); ok {
		for _, e := range t.Errors {
			AdjustErrorStatusCode(status, e)
		}
	}

	// Adjust status code when sealed
	if errwrap.Contains(err, consts.ErrSealed.Error()) {
		*status = http.StatusServiceUnavailable
	}

	// Adjust status code on
	if errwrap.Contains(err, "http: request body too large") {
		*status = http.StatusRequestEntityTooLarge
	}

	// Allow HTTPCoded error passthrough to specify a code
	if t, ok := err.(HTTPCodedError); ok {
		*status = t.Code()
	}
}
47961
func (o *GetAccountDefault) WithStatusCode(code int) *GetAccountDefault {
	o._statusCode = code
	return o
}
126886
func statusCodeFromGRPCError(err error) int {
	switch status.Code(err) {
	case codes.InvalidArgument: // code 3
		return http.StatusBadRequest
	case codes.NotFound: // code 5
		return http.StatusNotFound
	case codes.AlreadyExists: // code 6
		return http.StatusConflict
	case codes.PermissionDenied: // code 7
		return http.StatusForbidden
	case codes.FailedPrecondition: // code 9
		return http.StatusBadRequest
	case codes.Unauthenticated: // code 16
		return http.StatusUnauthorized
	case codes.OutOfRange: // code 11
		return http.StatusBadRequest
	case codes.Unimplemented: // code 12
		return http.StatusNotImplemented
	case codes.Unavailable: // code 14
		return http.StatusServiceUnavailable
	default:
		if e, ok := err.(causer); ok {
			return statusCodeFromGRPCError(e.Cause())
		}
		// codes.Canceled(1)
		// codes.Unknown(2)
		// codes.DeadlineExceeded(4)
		// codes.ResourceExhausted(8)
		// codes.Aborted(10)
		// codes.Internal(13)
		// codes.DataLoss(15)
		return http.StatusInternalServerError
	}
}
519930
func (o *CreateTaskDefault) WithStatusCode(code int) *CreateTaskDefault {
	o._statusCode = code
	return o
}
285907
func (o *FindDefault) WithStatusCode(code int) *FindDefault {
	o._statusCode = code
	return o
}
1373866
func statusCodeFromDistributionError(err error) int {
	switch errs := err.(type) {
	case errcode.Errors:
		if len(errs) < 1 {
			return http.StatusInternalServerError
		}
		if _, ok := errs[0].(errcode.ErrorCoder); ok {
			return statusCodeFromDistributionError(errs[0])
		}
	case errcode.ErrorCoder:
		return errs.ErrorCode().Descriptor().HTTPStatusCode
	default:
		if e, ok := err.(causer); ok {
			return statusCodeFromDistributionError(e.Cause())
		}
	}
	return http.StatusInternalServerError
}
1018612
func (r *httpJSONResponseElement) StatusCode() int {
	if r.statusCode == nil {
		statusCode := 200
		// Look for "error" field
		if errorFieldJSON, found := r.bodyObject["error"]; found {
			var hasError bool
			if err := json.Unmarshal(*errorFieldJSON, &hasError); err == nil && hasError {
				// We have an error, look for code field
				statusCode = 500
				if codeFieldJSON, found := r.bodyObject["code"]; found {
					var code int
					if err := json.Unmarshal(*codeFieldJSON, &code); err == nil {
						statusCode = code
					}
				}
			}
		}
		r.statusCode = &statusCode
	}
	return *r.statusCode
}
386621
func CheckStatus(r *HttpResponse, err error) (*HttpResponse, error) {
	if err != nil {
		return r, err
	}

	return r, r.ResponseError()
}
844230
func (r *Response) StatusCode() int {
	if r.RawResponse == nil {
		return 0
	}

	return r.RawResponse.StatusCode
}
997145
func GetStatusCode(err error, default_code int) int {
	rv := errors.GetData(err, statusCode)
	sc, ok := rv.(int)
	if ok {
		return sc
	}
	return default_code
}
1235601
func HTTPError(w http.ResponseWriter, code int) {
	msg := http.StatusText(code)
	Errorln(msg)
	m := make(map[string]string)
	m["status"] = "error"
	m["error"] = msg
	b, _ := json.MarshalIndent(m, "", "\t")
	http.Error(w, string(b), code)
}
1052390
func (o *LogoutUserDefault) WithStatusCode(code int) *LogoutUserDefault {
	o._statusCode = code
	return o
}
294828
func (o *GetItemsDefault) WithStatusCode(code int) *GetItemsDefault {
	o._statusCode = code
	return o
}
594025
func (o *UploadTaskFileDefault) WithStatusCode(code int) *UploadTaskFileDefault {
	o._statusCode = code
	return o
}
535696
func (o *CreateDefault) WithStatusCode(code int) *CreateDefault {
	o._statusCode = code
	return o
}
1058667
func (s *AccountModification) SetErrorCode(v string) *AccountModification {
	s.ErrorCode = &v
	return s
}
886920
func (o *GetOrdersForItemDefault) WithStatusCode(code int) *GetOrdersForItemDefault {
	o._statusCode = code
	return o
}