func bakeryError(err error) error {
	if params.ErrCode(err) != params.CodeDischargeRequired {
		return err
	}
	errResp := errors.Cause(err).(*params.Error)
	if errResp.Info == nil {
		return errors.Annotate(err, "no error info found in discharge-required response error")
	}
	// It's a discharge-required error, so make an appropriate httpbakery
	// error from it.
	var info params.DischargeRequiredErrorInfo
	if errUnmarshal := errResp.UnmarshalInfo(&info); errUnmarshal != nil {
		return errors.Annotate(err, "unable to extract macaroon details from discharge-required response error")
	}

	bakeryErr := &httpbakery.Error{
		Message: err.Error(),
		Code:    httpbakery.ErrDischargeRequired,
		Info: &httpbakery.ErrorInfo{
			MacaroonPath: info.MacaroonPath,
		},
	}
	if info.Macaroon != nil || info.BakeryMacaroon != nil {
		// Prefer the newer bakery.v2 macaroon.
		dcMac := info.BakeryMacaroon
		if dcMac == nil {
			dcMac, err = bakery.NewLegacyMacaroon(info.Macaroon)
			if err != nil {
				return errors.Annotate(err, "unable to create legacy macaroon details from discharge-required response error")
			}
		}
		bakeryErr.Info.Macaroon = dcMac
	}
	return bakeryErr
}
// bakeryError translates any discharge-required error into
// an error value that the httpbakery package will recognize.
// Other errors are returned unchanged.
bakeryError translates any discharge-required error into
an error value that the httpbakery package will recognize.
Other errors are returned unchanged.
// bakeryError translates any discharge - required error into // an error value that the httpbakery package will recognize . // Other errors are returned unchanged .
func bakeryError(err error) error {
	if params.ErrCode(err) != params.CodeDischargeRequired {
		return err
	}
	errResp := errors.Cause(err).(*params.Error)
	if errResp.Info == nil {
		return errors.Annotate(err, "no error info found in discharge-required response error")
	}
	var info params.DischargeRequiredErrorInfo
	if errUnmarshal := errResp.UnmarshalInfo(&info); errUnmarshal != nil {
		return errors.Annotate(err, "unable to extract macaroon details from discharge-required response error")
	}
	bakeryErr := &httpbakery.Error{
		Message: err.Error(),
		Code:    httpbakery.ErrDischargeRequired,
		Info: &httpbakery.ErrorInfo{
			MacaroonPath: info.MacaroonPath,
		},
	}
	if info.Macaroon != nil || info.BakeryMacaroon != nil {
		dcMac := info.BakeryMacaroon
		if dcMac == nil {
			dcMac, err = bakery.NewLegacyMacaroon(info.Macaroon)
			if err != nil {
				return errors.Annotate(err, "unable to create legacy macaroon details from discharge-required response error")
			}
		}
		bakeryErr.Info.Macaroon = dcMac
	}
	return bakeryErr
}
func bakeryError ( err error ) error { if params . ErrCode ( err ) != params . CodeDischargeRequired { return err } errResp := errors . Cause ( err ) . ( * params . Error ) if errResp . Info == nil { return errors . Annotate ( err , " " ) } var info params . DischargeRequiredErrorInfo if errUnmarshal := errResp . UnmarshalInfo ( & info ) ; errUnmarshal != nil { return errors . Annotate ( err , " " ) } bakeryErr := & httpbakery . Error { Message : err . Error ( ) , Code : httpbakery . ErrDischargeRequired , Info : & httpbakery . ErrorInfo { MacaroonPath : info . MacaroonPath , } , } if info . Macaroon != nil || info . BakeryMacaroon != nil { dcMac := info . BakeryMacaroon if dcMac == nil { dcMac , err = bakery . NewLegacyMacaroon ( info . Macaroon ) if err != nil { return errors . Annotate ( err , " " ) } } bakeryErr . Info . Macaroon = dcMac } return bakeryErr }
bakeryError translates any discharge-required error into
an error value that the httpbakery package will recognize.
bakeryError translates any discharge - required error into an error value that the httpbakery package will recognize .
// It's a discharge-required error, so make an appropriate httpbakery // error from it. // Prefer the newer bakery.v2 macaroon.