summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroenwijenbergh@protonmail.com>2024-05-06 14:49:46 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-05-24 13:25:11 +0200
commit9a0576db3b869d16dd523f812abf7771d8be66a9 (patch)
treeea1dd60cac7c181bafc6bc371e0be782b3c7c2dc
parenta2abd97078f9652c8b1cce629ebc4ac090de3008 (diff)
API Connect: Move errors.New to vars
-rw-r--r--internal/api/api.go10
1 files changed, 8 insertions, 2 deletions
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