// writeError writes the error to the response.
// If the error implements HTTPError, it will set the HTTP status as the result of the StatusCode() call of the error.
// Otherwise, the HTTP status will be set as http.StatusInternalServerError.
777336
func writeError(c *routing.Context, err error) {
	if httpError, ok := err.(routing.HTTPError); ok {
		c.Response.WriteHeader(httpError.StatusCode())
	} else {
		c.Response.WriteHeader(http.StatusInternalServerError)
	}
	c.Write(err)
}
89798
func (e *httpError) Write(response *restful.Response) {
	response.WriteErrorString(e.statusCode, e.message)
}
1208861
func writeError(w http.ResponseWriter, statusCode int, msg string, args ...interface{}) {
	w.WriteHeader(statusCode)
	w.Write([]byte(fmt.Sprintf(msg, args...)))
}
1116915
func (api *API) RespondError(err error) error {
	var response errorResponse
	response.Error = err.Error()

	return sendSerializedJSONMessage(response, api.Writer)
}
725815
func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values url.Values) bool {
	code := httpCode(handler, method, url, values)
	if code == -1 {
		return false
	}
	return code >= http.StatusBadRequest
}
729621
func otherErrorToHTTPError(err error) *httpError {
	var httpErr httpError
	switch err {
	case app.ErrNotFound:
		httpErr.statusCode = http.StatusBadRequest
	case app.ErrExists:
		httpErr.statusCode = http.StatusForbidden
	case app.ErrNoAccess:
		httpErr.statusCode = http.StatusUnauthorized
	default:
		httpErr.statusCode = http.StatusInternalServerError
	}

	httpErr.message = err.Error()
	return &httpErr
}
803501
func ReadError(statusCode int, re []byte) error {
	var e error
	switch statusCode {
	case http.StatusNotFound:
		e = &NotFoundError{Message: string(re)}
	case http.StatusBadRequest:
		e = &BadParameterError{Message: string(re)}
	case http.StatusNotImplemented:
		e = &NotImplementedError{Message: string(re)}
	case http.StatusPreconditionFailed:
		e = &CompareFailedError{Message: string(re)}
	case http.StatusForbidden:
		e = &AccessDeniedError{Message: string(re)}
	case http.StatusConflict:
		e = &AlreadyExistsError{Message: string(re)}
	case http.StatusTooManyRequests:
		e = &LimitExceededError{Message: string(re)}
	case http.StatusGatewayTimeout:
		e = &ConnectionProblemError{Message: string(re)}
	default:
		if statusCode < 200 || statusCode > 299 {
			return Errorf(string(re))
		}
		return nil
	}
	return unmarshalError(e, re)
}
60443
func (errs Errors) Error() string {
	var b bytes.Buffer
	for i, e := range errs {
		if i > 0 {
			b.WriteRune('\n')
		}
		b.WriteString(e.Error())
	}
	return b.String()
}
422
func (apigError *Error) Error() string {
	bytes, bytesErr := json.Marshal(apigError)
	if bytesErr != nil {
		bytes = []byte(http.StatusText(http.StatusInternalServerError))
	}
	return string(bytes)
}
108559
func jsonError(err error) string {
	var errMsg struct {
		Err string `json:"err"`
	}
	errMsg.Err = err.Error()

	data, _ := json.Marshal(&errMsg)
	return string(data)
}
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)
}
692892
func WriteError(w http.ResponseWriter, code int, err string) {
	w.WriteHeader(code)

	WriteJSON(w, map[string]string{
		"error": err,
	})
}
4050
func ResponseError(err error) *Response {
	return &Response{ResponseError: err, BodyClosed: true, Response: &http.Response{}}
}
4951
func replyError(c context.Context, rw http.ResponseWriter, err error) {
	logging.Errorf(c, "Error while processing PubSub notification - %s", err)
	if transient.Tag.In(err) {
		http.Error(rw, err.Error(), http.StatusInternalServerError)
	} else {
		http.Error(rw, err.Error(), http.StatusBadRequest)
	}
}
120189
func InternalError(w http.ResponseWriter, req *http.Request, err error) {
	http.Error(w, sanitizer.Replace(fmt.Sprintf("Internal Server Error: %q: %v", req.RequestURI, err)),
		http.StatusInternalServerError)
	utilruntime.HandleError(err)
}
273139
func (e *HTTPError) Error() string {
	var b bytes.Buffer

	fmt.Fprintf(&b, "%d - %s:", e.StatusCode, http.StatusText(e.StatusCode))

	for _, e := range e.Errors {
		fmt.Fprintf(&b, "\n")

		if e.ID != "" {
			fmt.Fprintf(&b, "\n    ID:     %s", e.ID)
		}

		if e.Title != "" {
			fmt.Fprintf(&b, "\n    Title:  %s", e.Title)
		}

		if e.Detail != "" {
			fmt.Fprintf(&b, "\n    Detail: %s", e.Detail)
		}

		if e.Code != "" {
			fmt.Fprintf(&b, "\n    Code:   %s", e.Code)
		}

		if e.Meta != nil {
			fmt.Fprintf(&b, "\n    Meta:   %v", *e.Meta)
		}
	}

	return b.String()
}
1139319
func ReplyError(w http.ResponseWriter, err error) {
	response, status := responseAndStatusFor(err)
	Reply(w, response, status)
}