mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-14 17:39:12 +02:00
[management] Say what went wrong when loading a provider's models fails
Pressing "Load models from provider" against a key the vendor refuses answered "internal server error". Every outcome on that path is the operator's own key or upstream, so a 500 was wrong twice over: it told them the server broke, and it named nothing they could act on. The failures are already typed and already have sentences written for them — the save-time check translates the same set. Discovery now runs them through the same classifier, so the button reports a refused credential or an unreachable url in the words the form uses elsewhere. ErrNoDiscovery and ErrInvalidRequest pass through untouched. The handler maps both already, and a provider with no listing endpoint is a fact about the catalog entry rather than a failure — the caller falls back to the catalog's own models instead of showing an error at all.
This commit is contained in:
@@ -49,6 +49,32 @@ func (m *managerImpl) checkProviderCredential(ctx context.Context, provider *typ
|
||||
return status.Errorf(status.InvalidArgument, "%s", message)
|
||||
}
|
||||
|
||||
// discoveryFailure renders a failed model listing for the operator who pressed
|
||||
// the button. Every outcome here is something they did or configured — a key
|
||||
// the vendor refused, an upstream that does not answer — so it owes them the
|
||||
// same sentence a refused save gives, not the generic 500 an unclassified
|
||||
// error turns into.
|
||||
//
|
||||
// ErrNoDiscovery and ErrInvalidRequest pass through untouched: the handler
|
||||
// already maps them, and "this provider has no listing endpoint" is a fact
|
||||
// about the catalog rather than a failure to report as one.
|
||||
func discoveryFailure(ctx context.Context, catalogID string, err error) error {
|
||||
if errors.Is(err, modeldiscovery.ErrNoDiscovery) || errors.Is(err, modeldiscovery.ErrInvalidRequest) {
|
||||
return err
|
||||
}
|
||||
|
||||
message, _ := credentialCheckFailure(err)
|
||||
if message == "" {
|
||||
return err
|
||||
}
|
||||
|
||||
// The operator's message carries no status code, so the vendor's number is
|
||||
// recorded here or nowhere.
|
||||
log.WithContext(ctx).Infof("agent network model discovery for %s failed: %v", catalogID, err)
|
||||
|
||||
return status.Errorf(status.InvalidArgument, "%s", message)
|
||||
}
|
||||
|
||||
// credentialCheckFailure renders a discovery failure as the sentence the
|
||||
// provider form shows, and reports whether it should block the write.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user