func RespondWithError(w http.ResponseWriter, r *http.Request, userHttpCode int, format string, args ...interface{}) {
	// XXX this function needs to get an error in and a format + args
	// instead of what it is doing now.
	// So inError error, format string, args ...interface{}
	// if err == nil -> internal error using format + args
	// if err != nil -> if defined error -> return defined error + log.Errorf format+args
	// if err != nil -> if !defined error -> return + log.Errorf format+args
	if userErr, ok := args[0].(v1.UserError); ok {
		if userHttpCode == 0 {
			userHttpCode = http.StatusBadRequest
		}

		if len(userErr.ErrorContext) == 0 {
			log.Errorf("RespondWithError: %v %v",
				int64(userErr.ErrorCode),
				v1.ErrorStatus[userErr.ErrorCode])
		} else {
			log.Errorf("RespondWithError: %v %v: %v",
				int64(userErr.ErrorCode),
				v1.ErrorStatus[userErr.ErrorCode],
				strings.Join(userErr.ErrorContext, ", "))
		}

		util.RespondWithJSON(w, userHttpCode,
			v1.ErrorReply{
				ErrorCode:    int64(userErr.ErrorCode),
				ErrorContext: userErr.ErrorContext,
			})
		return
	}

	if pdError, ok := args[0].(v1.PDError); ok {
		pdErrorCode := convertErrorStatusFromPD(pdError.ErrorReply.ErrorCode)
		if pdErrorCode == v1.ErrorStatusInvalid {
			errorCode := time.Now().Unix()
			log.Errorf("%v %v %v %v Internal error %v: error "+
				"code from politeiad: %v", remoteAddr(r),
				r.Method, r.URL, r.Proto, errorCode,
				pdError.ErrorReply.ErrorCode)
			util.RespondWithJSON(w, http.StatusInternalServerError,
				v1.ErrorReply{
					ErrorCode: errorCode,
				})
			return
		}

		util.RespondWithJSON(w, pdError.HTTPCode,
			v1.ErrorReply{
				ErrorCode:    int64(pdErrorCode),
				ErrorContext: pdError.ErrorReply.ErrorContext,
			})
		return
	}

	errorCode := time.Now().Unix()
	ec := fmt.Sprintf("%v %v %v %v Internal error %v: ", remoteAddr(r),
		r.Method, r.URL, r.Proto, errorCode)
	log.Errorf(ec+format, args...)
	log.Errorf("Stacktrace: %s", debug.Stack())
	util.RespondWithJSON(w, http.StatusInternalServerError,
		v1.ErrorReply{
			ErrorCode: errorCode,
		})
}
// RespondWithError returns an HTTP error status to the client. If it's a user
// error, it returns a 4xx HTTP status and the specific user error code. If it's
// an internal server error, it returns 500 and an error code which is also
// outputted to the logs so that it can be correlated later if the user
// files a complaint.
RespondWithError returns an HTTP error status to the client. If it's a user
error, it returns a 4xx HTTP status and the specific user error code. If it's
an internal server error, it returns 500 and an error code which is also
outputted to the logs so that it can be correlated later if the user
files a complaint.
// RespondWithError returns an HTTP error status to the client . If it ' s a user // error it returns a 4xx HTTP status and the specific user error code . If it ' s // an internal server error it returns 500 and an error code which is also // outputted to the logs so that it can be correlated later if the user // files a complaint .
func RespondWithError(w http.ResponseWriter, r *http.Request, userHttpCode int, format string, args ...interface{}) {
	if userErr, ok := args[0].(v1.UserError); ok {
		if userHttpCode == 0 {
			userHttpCode = http.StatusBadRequest
		}
		if len(userErr.ErrorContext) == 0 {
			log.Errorf("RespondWithError: %v %v",
				int64(userErr.ErrorCode),
				v1.ErrorStatus[userErr.ErrorCode])
		} else {
			log.Errorf("RespondWithError: %v %v: %v",
				int64(userErr.ErrorCode),
				v1.ErrorStatus[userErr.ErrorCode],
				strings.Join(userErr.ErrorContext, ", "))
		}
		util.RespondWithJSON(w, userHttpCode,
			v1.ErrorReply{
				ErrorCode:    int64(userErr.ErrorCode),
				ErrorContext: userErr.ErrorContext,
			})
		return
	}
	if pdError, ok := args[0].(v1.PDError); ok {
		pdErrorCode := convertErrorStatusFromPD(pdError.ErrorReply.ErrorCode)
		if pdErrorCode == v1.ErrorStatusInvalid {
			errorCode := time.Now().Unix()
			log.Errorf("%v %v %v %v Internal error %v: error "+
				"code from politeiad: %v", remoteAddr(r),
				r.Method, r.URL, r.Proto, errorCode,
				pdError.ErrorReply.ErrorCode)
			util.RespondWithJSON(w, http.StatusInternalServerError,
				v1.ErrorReply{
					ErrorCode: errorCode,
				})
			return
		}
		util.RespondWithJSON(w, pdError.HTTPCode,
			v1.ErrorReply{
				ErrorCode:    int64(pdErrorCode),
				ErrorContext: pdError.ErrorReply.ErrorContext,
			})
		return
	}
	errorCode := time.Now().Unix()
	ec := fmt.Sprintf("%v %v %v %v Internal error %v: ", remoteAddr(r),
		r.Method, r.URL, r.Proto, errorCode)
	log.Errorf(ec+format, args...)
	log.Errorf("Stacktrace: %s", debug.Stack())
	util.RespondWithJSON(w, http.StatusInternalServerError,
		v1.ErrorReply{
			ErrorCode: errorCode,
		})
}
func RespondWithError ( w http . ResponseWriter , r * http . Request , userHttpCode int , format string , args ... interface { } ) { if userErr , ok := args [ 0 ] . ( v1 . UserError ) ; ok { if userHttpCode == 0 { userHttpCode = http . StatusBadRequest } if len ( userErr . ErrorContext ) == 0 { log . Errorf ( " " , int64 ( userErr . ErrorCode ) , v1 . ErrorStatus [ userErr . ErrorCode ] ) } else { log . Errorf ( " " , int64 ( userErr . ErrorCode ) , v1 . ErrorStatus [ userErr . ErrorCode ] , strings . Join ( userErr . ErrorContext , " " ) ) } util . RespondWithJSON ( w , userHttpCode , v1 . ErrorReply { ErrorCode : int64 ( userErr . ErrorCode ) , ErrorContext : userErr . ErrorContext , } ) return } if pdError , ok := args [ 0 ] . ( v1 . PDError ) ; ok { pdErrorCode := convertErrorStatusFromPD ( pdError . ErrorReply . ErrorCode ) if pdErrorCode == v1 . ErrorStatusInvalid { errorCode := time . Now ( ) . Unix ( ) log . Errorf ( " " + " " , remoteAddr ( r ) , r . Method , r . URL , r . Proto , errorCode , pdError . ErrorReply . ErrorCode ) util . RespondWithJSON ( w , http . StatusInternalServerError , v1 . ErrorReply { ErrorCode : errorCode , } ) return } util . RespondWithJSON ( w , pdError . HTTPCode , v1 . ErrorReply { ErrorCode : int64 ( pdErrorCode ) , ErrorContext : pdError . ErrorReply . ErrorContext , } ) return } errorCode := time . Now ( ) . Unix ( ) ec := fmt . Sprintf ( " " , remoteAddr ( r ) , r . Method , r . URL , r . Proto , errorCode ) log . Errorf ( ec + format , args ... ) log . Errorf ( " " , debug . Stack ( ) ) util . RespondWithJSON ( w , http . StatusInternalServerError , v1 . ErrorReply { ErrorCode : errorCode , } ) }
RespondWithError returns an HTTP error status to the client.
RespondWithError returns an HTTP error status to the client .
// XXX this function needs to get an error in and a format + args // instead of what it is doing now. // So inError error, format string, args ...interface{} // if err == nil -> internal error using format + args // if err != nil -> if defined error -> return defined error + log.Errorf format+args // if err != nil -> if !defined error -> return + log.Errorf format+args