github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/command/v2/shared/handle_error.go (about) 1 package shared 2 3 import ( 4 "github.com/liamawhite/cli-with-i18n/actor/actionerror" 5 "github.com/liamawhite/cli-with-i18n/actor/pushaction" 6 "github.com/liamawhite/cli-with-i18n/actor/sharedaction" 7 "github.com/liamawhite/cli-with-i18n/actor/v2action" 8 "github.com/liamawhite/cli-with-i18n/api/cloudcontroller/ccerror" 9 "github.com/liamawhite/cli-with-i18n/api/uaa" 10 "github.com/liamawhite/cli-with-i18n/command/translatableerror" 11 "github.com/liamawhite/cli-with-i18n/util/manifest" 12 ) 13 14 func HandleError(err error) error { 15 switch e := err.(type) { 16 case ccerror.APINotFoundError: 17 return translatableerror.APINotFoundError(e) 18 case ccerror.RequestError: 19 return translatableerror.APIRequestError(e) 20 case ccerror.SSLValidationHostnameError: 21 return translatableerror.SSLCertError(e) 22 case ccerror.UnverifiedServerError: 23 return translatableerror.InvalidSSLCertError{API: e.URL} 24 25 case ccerror.JobFailedError: 26 return translatableerror.JobFailedError(e) 27 case ccerror.JobTimeoutError: 28 return translatableerror.JobTimeoutError{JobGUID: e.JobGUID} 29 30 case uaa.BadCredentialsError: 31 return translatableerror.BadCredentialsError{} 32 case uaa.InvalidAuthTokenError: 33 return translatableerror.InvalidRefreshTokenError{} 34 35 case sharedaction.NotLoggedInError: 36 return translatableerror.NotLoggedInError(e) 37 case sharedaction.NoOrganizationTargetedError: 38 return translatableerror.NoOrganizationTargetedError(e) 39 case sharedaction.NoSpaceTargetedError: 40 return translatableerror.NoSpaceTargetedError(e) 41 42 case actionerror.ApplicationNotFoundError: 43 return translatableerror.ApplicationNotFoundError{Name: e.Name} 44 case v2action.OrganizationNotFoundError: 45 return translatableerror.OrganizationNotFoundError{Name: e.Name} 46 case v2action.SecurityGroupNotFoundError: 47 return translatableerror.SecurityGroupNotFoundError(e) 48 case v2action.ServiceInstanceNotFoundError: 49 return translatableerror.ServiceInstanceNotFoundError(e) 50 case v2action.SpaceNotFoundError: 51 return translatableerror.SpaceNotFoundError{Name: e.Name} 52 case v2action.StackNotFoundError: 53 return translatableerror.StackNotFoundError(e) 54 case actionerror.HTTPHealthCheckInvalidError: 55 return translatableerror.HTTPHealthCheckInvalidError{} 56 case v2action.RouteInDifferentSpaceError: 57 return translatableerror.RouteInDifferentSpaceError(e) 58 case v2action.FileChangedError: 59 return translatableerror.FileChangedError(e) 60 case sharedaction.EmptyDirectoryError: 61 return translatableerror.EmptyDirectoryError(e) 62 case v2action.DomainNotFoundError: 63 return translatableerror.DomainNotFoundError(e) 64 case actionerror.NoMatchingDomainError: 65 return translatableerror.NoMatchingDomainError(e) 66 case actionerror.InvalidHTTPRouteSettings: 67 return translatableerror.PortNotAllowedWithHTTPDomainError(e) 68 69 case pushaction.AppNotFoundInManifestError: 70 return translatableerror.AppNotFoundInManifestError(e) 71 case pushaction.CommandLineOptionsWithMultipleAppsError: 72 return translatableerror.CommandLineArgsWithMultipleAppsError{} 73 case pushaction.NoDomainsFoundError: 74 return translatableerror.NoDomainsFoundError{} 75 case pushaction.NonexistentAppPathError: 76 return translatableerror.FileNotFoundError(e) 77 case pushaction.MissingNameError: 78 return translatableerror.RequiredNameForPushError{} 79 case pushaction.UploadFailedError: 80 return translatableerror.UploadFailedError{Err: HandleError(e.Err)} 81 82 case manifest.ManifestCreationError: 83 return translatableerror.ManifestCreationError(e) 84 } 85 86 return err 87 }