add unpacker reflect check

This commit is contained in:
runzexia 2018-06-12 14:50:12 +08:00
parent 05aacd4b8c
commit 668c19eca1
1 changed files with 7 additions and 0 deletions

View File

@ -78,9 +78,16 @@ func (u *Unpacker) parseResponse() error {
}
func (u *Unpacker) parseError() error {
if !u.output.IsValid() {
return fmt.Errorf("output fmt error")
}
retCodeValue := u.output.Elem().FieldByName("RetCode")
messageValue := u.output.Elem().FieldByName("Message")
if !retCodeValue.IsValid() || !messageValue.IsValid() {
return fmt.Errorf("can not get retcode/message")
}
if retCodeValue.Elem().IsValid() && retCodeValue.Type().String() == "*int" &&
messageValue.Elem().IsValid() && messageValue.Type().String() == "*string" &&
retCodeValue.Elem().Int() != 0 {