-
Notifications
You must be signed in to change notification settings - Fork 928
/
handle_error.go
47 lines (42 loc) · 1.5 KB
/
handle_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package shared
import (
"encoding/json"
"code.cloudfoundry.org/cli/actor/pluginaction"
"code.cloudfoundry.org/cli/api/plugin/pluginerror"
)
func HandleError(err error) error {
switch e := err.(type) {
case *json.SyntaxError:
return JSONSyntaxError{Err: e}
case pluginerror.RawHTTPStatusError:
return DownloadPluginHTTPError{Message: e.Status}
case pluginerror.SSLValidationHostnameError:
return DownloadPluginHTTPError{Message: e.Error()}
case pluginerror.UnverifiedServerError:
return DownloadPluginHTTPError{Message: e.Error()}
case pluginaction.AddPluginRepositoryError:
return AddPluginRepositoryError{Name: e.Name, URL: e.URL, Message: e.Message}
case pluginaction.GettingPluginRepositoryError:
return GettingPluginRepositoryError{Name: e.Name, Message: e.Message}
case pluginaction.NoCompatibleBinaryError:
return NoCompatibleBinaryError{}
case pluginaction.PluginCommandsConflictError:
return PluginCommandsConflictError{
PluginName: e.PluginName,
PluginVersion: e.PluginVersion,
CommandNames: e.CommandNames,
CommandAliases: e.CommandAliases,
}
case pluginaction.PluginInvalidError:
return PluginInvalidError{Err: e.Err}
case pluginaction.PluginNotFoundError:
return PluginNotFoundError{PluginName: e.PluginName}
case pluginaction.RepositoryNameTakenError:
return RepositoryNameTakenError{Name: e.Name}
case pluginaction.RepositoryNotRegisteredError:
return RepositoryNotRegisteredError{Name: e.Name}
case PluginInstallationCancelled:
return nil
}
return err
}