diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-02-06 14:43:06 +0100 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-02-19 14:15:07 +0100 |
| commit | 3fd29f3e1c963196cac69fcbb9d68116f7ea80ec (patch) | |
| tree | 7cb586d304167e4198166ff17dc79d33122a75e5 /internal/discovery | |
| parent | 2337dcde60a710d2f65d3fe1107811202e34c633 (diff) | |
All: Prepare to get rid of go-errors/errors lib
Diffstat (limited to 'internal/discovery')
| -rw-r--r-- | internal/discovery/discovery.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index 06548f9..d89f0f5 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -10,7 +10,6 @@ import ( "github.com/eduvpn/eduvpn-common/internal/http" "github.com/eduvpn/eduvpn-common/internal/verify" discotypes "github.com/eduvpn/eduvpn-common/types/discovery" - "github.com/go-errors/errors" ) // HasCache denotes whether or not we have an embedded cache available @@ -76,8 +75,7 @@ func (discovery *Discovery) file(ctx context.Context, jsonFile string, previousV // Parse JSON to extract version and list if err = json.Unmarshal(body, structure); err != nil { - return errors.WrapPrefix(err, - fmt.Sprintf("failed parsing discovery file: %s from the server", jsonFile), 0) + return fmt.Errorf("failed parsing discovery file: '%s' from the server with error: %w", jsonFile, err) } return nil @@ -122,7 +120,15 @@ func (discovery *Discovery) ServerByURL( return ¤tServer, nil } } - return nil, errors.Errorf("no server of type '%s' at URL '%s'", srvType, baseURL) + return nil, fmt.Errorf("no server of type '%s' at URL '%s'", srvType, baseURL) +} + +type CountryNotFoundError struct { + CountryCode string +} + +func (cnf *CountryNotFoundError) Error() string { + return fmt.Sprintf("no secure internet server with country code: '%s'", cnf.CountryCode) } // ServerByCountryCode returns the discovery server by the country code @@ -133,7 +139,7 @@ func (discovery *Discovery) ServerByCountryCode(countryCode string) (*discotypes return &srv, nil } } - return nil, errors.Errorf("no server of type 'secure_internet' with country code '%s'", countryCode) + return nil, &CountryNotFoundError{CountryCode: countryCode} } // orgByID returns the discovery organization by the organization ID @@ -144,7 +150,7 @@ func (discovery *Discovery) orgByID(orgID string) (*discotypes.Organization, err return &org, nil } } - return nil, errors.Errorf("no secure internet home found in organization '%s'", orgID) + return nil, fmt.Errorf("no secure internet home found in organization '%s'", orgID) } // SecureHomeArgs returns the secure internet home server arguments: @@ -189,7 +195,7 @@ func (discovery *Discovery) previousOrganizations() (*discotypes.Organizations, // We do not have a cached struct, this we need to get it using the embedded JSON var eo discotypes.Organizations if err := json.Unmarshal(eOrganizations, &eo); err != nil { - return nil, errors.WrapPrefix(err, "failed parsing discovery organizations from the embedded cache", 0) + return nil, fmt.Errorf("failed parsing discovery organizations from the embedded cache with error: %w", err) } discovery.OrganizationList = eo return &eo, nil @@ -205,7 +211,7 @@ func (discovery *Discovery) previousServers() (*discotypes.Servers, error) { // We do not have a cached struct, this we need to get it using the embedded JSON var es discotypes.Servers if err := json.Unmarshal(eServers, &es); err != nil { - return nil, errors.WrapPrefix(err, "failed parsing discovery servers from the embedded cache", 0) + return nil, fmt.Errorf("failed parsing discovery servers from the embedded cache with error: %w", err) } discovery.ServerList = es return &es, nil |
