Skip to content

Commit

Permalink
feat: add error judgment (#574)
Browse files Browse the repository at this point in the history
Signed-off-by: jyjiangkai <[email protected]>
  • Loading branch information
hwjiangkai authored Mar 24, 2023
1 parent 19445de commit 28c5b79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/errors/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ func Is(err error, target error) bool {
}

func FromError(err error) (*ErrorType, bool) {
if err == nil {
return nil, true
}
if errType, ok := err.(*ErrorType); ok {
return errType, true
}

if errStatus, ok := status.FromError(err); ok {
if errType, ok := Convert(errStatus.Message()); ok {
return errType, true
}
}

return ErrUnknown.WithMessage(err.Error()), false
}

Expand Down
3 changes: 3 additions & 0 deletions vsctl/command/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func IsDNS1123Subdomain(value string) bool {
}

func Error(err error) string {
if err == nil {
return ""
}
e, _ := errors.FromError(err)
if e.Message == "" {
return e.Description
Expand Down

0 comments on commit 28c5b79

Please sign in to comment.