// WriteErrorCode writes an error to ResponseWriter and forces an error code.
437969
func (h *JSONWriter) WriteErrorCode(w http.ResponseWriter, r *http.Request, code int, err interface{}) {
	if err == nil {
		err = toError(err)
	}

	if code == 0 {
		code = http.StatusInternalServerError
	}

	// All errors land here, so it's a really good idea to do the logging here as well!
	h.Reporter(h.logger, "An error occurred while handling a request")(w, r, code, toError(err))

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(code)

	// Enhancing must happen after logging or context will be lost.
	if h.ErrorEnhancer != nil {
		err = h.ErrorEnhancer(r, toError(err))
	}

	if err := json.NewEncoder(w).Encode(err); err != nil {
		// There was an error, but there's actually not a lot we can do except log that this happened.
		h.Reporter(h.logger, "Could not write jsonError to response writer")(w, r, code, errors.WithStack(err))
	}
}
405772
func (s *WorkspaceImage) SetErrorCode(v string) *WorkspaceImage {
	s.ErrorCode = &v
	return s
}
45475
func writeErrorResponse(ctx context.Context, w http.ResponseWriter, err APIError, reqURL *url.URL, browser bool) {
	switch err.Code {
	case "SlowDown", "XMinioServerNotInitialized", "XMinioReadQuorum", "XMinioWriteQuorum":
		// Set retry-after header to indicate user-agents to retry request after 120secs.
		// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
		w.Header().Set("Retry-After", "120")
	case "AccessDenied":
		// The request is from browser and also if browser
		// is enabled we need to redirect.
		if browser {
			w.Header().Set("Location", minioReservedBucketPath+reqURL.Path)
			w.WriteHeader(http.StatusTemporaryRedirect)
			return
		}
	}

	// Generate error response.
	errorResponse := getAPIErrorResponse(ctx, err, reqURL.Path,
		w.Header().Get(responseRequestIDKey), w.Header().Get(responseDeploymentIDKey))
	encodedErrorResponse := encodeResponse(errorResponse)
	writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeXML)
}
960385
func (h *JSONWriter) WriteError(w http.ResponseWriter, r *http.Request, err interface{}) {
	if s, ok := errors.Cause(toError(err)).(statusCodeCarrier); ok {
		h.WriteErrorCode(w, r, s.StatusCode(), err)
		return
	}

	h.WriteErrorCode(w, r, http.StatusInternalServerError, err)
	return
}
1304212
func sendError(rw http.ResponseWriter, code int, err error) {
	resp := errorResponse{Error: errorEntity{Code: code}}
	if err != nil {
		resp.Error.Message = err.Error()
	}
	sendResponse(rw, code, resp)
}
977371
func (h *JSONWriter) WriteCode(w http.ResponseWriter, r *http.Request, code int, e interface{}) {
	js, err := json.Marshal(e)
	if err != nil {
		h.WriteError(w, r, errors.WithStack(err))
		return
	}

	if code == 0 {
		code = http.StatusOK
	}

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(code)
	w.Write(js)
}
70077
func (s *FailedCreateWorkspaceRequest) SetErrorCode(v string) *FailedCreateWorkspaceRequest {
	s.ErrorCode = &v
	return s
}
111171
func writeError(w http.ResponseWriter, status int, err error) {
	w.WriteHeader(status)
	enc := json.NewEncoder(w)
	resp := baseapitypes.Error{
		Type: baseapitypes.InternalServerError,
		Err:  []string{err.Error()},
	}

	enc.Encode(resp)
}
693720
func ErrorToCode(err error) int {
	switch {
	case IsAggregate(err):
		return http.StatusGatewayTimeout
	case IsNotFound(err):
		return http.StatusNotFound
	case IsBadParameter(err) || IsOAuth2(err):
		return http.StatusBadRequest
	case IsNotImplemented(err):
		return http.StatusNotImplemented
	case IsCompareFailed(err):
		return http.StatusPreconditionFailed
	case IsAccessDenied(err):
		return http.StatusForbidden
	case IsAlreadyExists(err):
		return http.StatusConflict
	case IsLimitExceeded(err):
		return http.StatusTooManyRequests
	case IsConnectionProblem(err):
		return http.StatusGatewayTimeout
	default:
		return http.StatusInternalServerError
	}
}
791666
func WriteErrorResponse(statusCode int, message string, w http.ResponseWriter) {
	var errstr []string

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(statusCode)
	errstr = append(errstr, http.StatusText(statusCode))
	resp := ErrorResponse{
		Status:  http.StatusText(statusCode),
		Message: message,
		Errors:  errstr,
	}
	json.NewEncoder(w).Encode(resp)
}
3570
func SendError(w http.ResponseWriter, data interface{}, rCode int) {
	rw := responseWriter{
		ResponseWriter: w,
		code:           rCode,
	}

	err := json.NewEncoder(rw).Encode(errOutput{data, rCode})
	if err != nil {
		/*
			In case of encoding error, send "internal server error" after
			logging the actual error.
		*/
		LOGHANDLER.Error(err)
		R500(w, ErrInternalServer)
	}
}
1231213
func (s *UserStackAssociationError) SetErrorCode(v string) *UserStackAssociationError {
	s.ErrorCode = &v
	return s
}
195061
func (et *ErrorTracker) Write(p []byte) (n int, err error) {
	if et.err != nil {
		return 0, et.err
	}
	n, err = et.Writer.Write(p)
	if err != nil {
		et.err = err
	}
	return n, err
}
892974
func (s *Job) SetErrorCode(v int64) *Job {
	s.ErrorCode = &v
	return s
}
1342110
func (s *FailedWorkspaceChangeRequest) SetErrorCode(v string) *FailedWorkspaceChangeRequest {
	s.ErrorCode = &v
	return s
}
318894
func (s *InstanceAssociationStatusInfo) SetErrorCode(v string) *InstanceAssociationStatusInfo {
	s.ErrorCode = &v
	return s
}
349136
func (s *Diagnostics) SetErrorCode(v string) *Diagnostics {
	s.ErrorCode = &v
	return s
}