Skip to content

Commit

Permalink
add SetErrMsg to SDKError
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzuochao committed Jul 3, 2020
1 parent 852924e commit d9c5d08
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tea/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type SDKError struct {
Code *string
Message *string
Data *string
Stack *string
errMsg *string
}

// RuntimeObject is used for converting http configuration
Expand Down Expand Up @@ -178,6 +180,19 @@ func NewSDKError(obj map[string]interface{}) *SDKError {
return err
}

func (err *SDKError) SetErrMsg(msg string) {
err.errMsg = String(msg)
}

func (err *SDKError) Error() string {
if err.errMsg == nil {
str := fmt.Sprintf("SDKError:\n Code: %s\n Message: %s\n Data: %s\n",
StringValue(err.Code), StringValue(err.Message), StringValue(err.Data))
err.SetErrMsg(str)
}
return StringValue(err.errMsg)
}

// Return message of CastError
func (err *CastError) Error() string {
return StringValue(err.Message)
Expand Down Expand Up @@ -495,11 +510,6 @@ func setDialContext(runtime *RuntimeObject, port int) func(cxt context.Context,
}
}

func (err *SDKError) Error() string {
return fmt.Sprintf("SDKError:\n Code: %s\n Message: %s\n Data: %s\n",
StringValue(err.Code), StringValue(err.Message), StringValue(err.Data))
}

func ToObject(obj interface{}) map[string]interface{} {
result := make(map[string]interface{})
byt, _ := json.Marshal(obj)
Expand Down

0 comments on commit d9c5d08

Please sign in to comment.