From 9a0576db3b869d16dd523f812abf7771d8be66a9 Mon Sep 17 00:00:00 2001 From: Jeroen Wijenbergh Date: Mon, 6 May 2024 14:49:46 +0200 Subject: API Connect: Move errors.New to vars --- internal/api/api.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'internal/api') diff --git a/internal/api/api.go b/internal/api/api.go index a075153..9c24315 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -239,6 +239,12 @@ func protocolFromCT(ct string) (protocol.Protocol, error) { return protocol.Unknown, fmt.Errorf("invalid content type: %s", ct) } +// ErrNoProtocols is returned when a connect call is given with an empty protocol slice +var ErrNoProtocols = errors.New("no protocols supplied") + +// ErrUnknownProtocol is returned when the client in a connect gives an unknown protocol +var ErrUnknownProtocol = errors.New("unknown protocol supplied") + // Connect sends a /connect to an eduVPN server // `ctx` is the context used for cancellation // protos is the list of protocols supported and wanted by the client @@ -251,7 +257,7 @@ func (a *API) Connect(ctx context.Context, prof profiles.Profile, protos []proto } if len(protos) == 0 { - return nil, errors.New("no protocols supplied") + return nil, ErrNoProtocols } var wgKey *wgtypes.Key @@ -273,7 +279,7 @@ func (a *API) Connect(ctx context.Context, prof profiles.Profile, protos []proto case protocol.OpenVPN: hdrs.Add("accept", "application/x-openvpn-profile") default: - return nil, errors.New("unknown protocol supplied") + return nil, ErrUnknownProtocol } } // set prefer TCP -- cgit v1.2.3