// ResponseToError converts a stripe response to an Error.
484959
func (s *BackendImplementation) ResponseToError(res *http.Response, resBody []byte) error {
	var raw rawError
	if err := s.UnmarshalJSONVerbose(res.StatusCode, resBody, &raw); err != nil {
		return err
	}

	// no error in resBody
	if raw.E == nil {
		err := errors.New(string(resBody))
		s.LeveledLogger.Errorf("Unparsable error returned from Stripe: %v", err)
		return err
	}
	raw.E.HTTPStatusCode = res.StatusCode
	raw.E.RequestID = res.Header.Get("Request-Id")

	var typedError error
	switch raw.E.Type {
	case ErrorTypeAPI:
		typedError = &APIError{stripeErr: raw.E.Error}
	case ErrorTypeAPIConnection:
		typedError = &APIConnectionError{stripeErr: raw.E.Error}
	case ErrorTypeAuthentication:
		typedError = &AuthenticationError{stripeErr: raw.E.Error}
	case ErrorTypeCard:
		cardErr := &CardError{stripeErr: raw.E.Error}
		if raw.E.DeclineCode != nil {
			cardErr.DeclineCode = *raw.E.DeclineCode
		}
		typedError = cardErr
	case ErrorTypeInvalidRequest:
		typedError = &InvalidRequestError{stripeErr: raw.E.Error}
	case ErrorTypePermission:
		typedError = &PermissionError{stripeErr: raw.E.Error}
	case ErrorTypeRateLimit:
		typedError = &RateLimitError{stripeErr: raw.E.Error}
	}
	raw.E.Err = typedError

	s.LeveledLogger.Errorf("Error encountered from Stripe: %v", raw.E.Error)
	return raw.E.Error
}
682192
func (r Response) FormatError() error {
	if len(r.body) == 0 {
		return fmt.Errorf("Error: %v", r.err)
	}
	return fmt.Errorf("%v", strings.TrimSpace(string(r.body)))
}
202938
func (e ErrInvalidAPIResponse) Error() string {
	return fmt.Sprintf(
		"invalid response: %d from %s: %s, body: %s",
		e.actualCode,
		service,
		e.uri,
		e.body,
	)
}
1260875
func replyError(c context.Context, rw http.ResponseWriter, err error) {
	if transient.Tag.In(err) {
		rw.WriteHeader(http.StatusInternalServerError)
	} else {
		rw.WriteHeader(http.StatusBadRequest)
	}
	templates.MustRender(c, rw, "pages/error.html", templates.Args{
		"Error": err.Error(),
	})
}
606486
func ToQuicError(err error) *QuicError {
	switch e := err.(type) {
	case *QuicError:
		return e
	case ErrorCode:
		return Error(e, "")
	}
	return Error(InternalError, err.Error())
}
369537
func RequestError(level string, r *http.Request, err error) {
	std.RequestError(level, r, err)
}
334651
func (r *Response) Error() string {
	if r.ResponseError != nil {
		return r.ResponseError.Error()
	}
	return ""
}
1088057
func RenderError(w http.ResponseWriter) {
	data := map[string]interface{}{
		"Output": readErrorFile(),
	}

	w.Header().Set("Content-Type", "text/html")
	tpl := template.Must(template.New("ErrorPage").Parse(buildPageTpl))
	tpl.Execute(w, data)
}
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)
}
740013
func AsResponseError(err error) *ResponseError {
	if err == nil {
		return nil
	}
	message := err.Error()
	var code string
	switch errors.Cause(err) {
	case lease.ErrInvalid:
		code = "invalid"
	case globalclock.ErrConcurrentUpdate:
		code = "concurrent-update"
	default:
		code = "error"
	}
	return &ResponseError{
		Message: message,
		Code:    code,
	}
}
286359
func getSTSErrorResponse(err STSError, requestID string) STSErrorResponse {
	errRsp := STSErrorResponse{}
	errRsp.Error.Code = err.Code
	errRsp.Error.Message = err.Description
	errRsp.RequestID = requestID
	return errRsp
}
806484
func (e *ResponseError) Error() string {
	return fmt.Sprintf("%v %v: %d - %s",
		e.Response.Request.Method, e.Response.Request.URL,
		e.Response.StatusCode, e.errorMessage())
}
300606
func WriteError(w http.ResponseWriter, err error) {
	if IsAggregate(err) {
		for i := 0; i < maxHops; i++ {
			var aggErr Aggregate
			var ok bool
			if aggErr, ok = Unwrap(err).(Aggregate); !ok {
				break
			}
			errors := aggErr.Errors()
			if len(errors) == 0 {
				break
			}
			err = errors[0]
		}
	}
	replyJSON(w, ErrorToCode(err), err)
}
20164
func (r *responseIterator) Err() error {
	if r.response.Err != "" {
		return fmt.Errorf(r.response.Err)
	}

	return nil
}
4050
func ResponseError(err error) *Response {
	return &Response{ResponseError: err, BodyClosed: true, Response: &http.Response{}}
}
514178
func (pt *pollingTrackerBase) updateErrorFromResponse() {
	var err error
	if pt.resp.ContentLength != 0 {
		type respErr struct {
			ServiceError *ServiceError `json:"error"`
		}
		re := respErr{}
		defer pt.resp.Body.Close()
		var b []byte
		if b, err = ioutil.ReadAll(pt.resp.Body); err != nil || len(b) == 0 {
			goto Default
		}
		if err = json.Unmarshal(b, &re); err != nil {
			goto Default
		}
		// unmarshalling the error didn't yield anything, try unwrapped error
		if re.ServiceError == nil {
			err = json.Unmarshal(b, &re.ServiceError)
			if err != nil {
				goto Default
			}
		}
		// the unmarshaller will ensure re.ServiceError is non-nil
		// even if there was no content unmarshalled so check the code.
		if re.ServiceError.Code != "" {
			pt.Err = re.ServiceError
			return
		}
	}
Default:
	se := &ServiceError{
		Code:    pt.pollingStatus(),
		Message: "The async operation failed.",
	}
	if err != nil {
		se.InnerError = make(map[string]interface{})
		se.InnerError["unmarshalError"] = err.Error()
	}
	// stick the response body into the error object in hopes
	// it contains something useful to help diagnose the failure.
	if len(pt.rawBody) > 0 {
		se.AdditionalInfo = []map[string]interface{}{
			pt.rawBody,
		}
	}
	pt.Err = se
}
161295
func writeSTSErrorResponse(w http.ResponseWriter, err STSError) {
	// Generate error response.
	stsErrorResponse := getSTSErrorResponse(err, w.Header().Get(responseRequestIDKey))
	encodedErrorResponse := encodeResponse(stsErrorResponse)
	writeResponse(w, err.HTTPStatusCode, encodedErrorResponse, mimeXML)
}