move check to else, move output nil check to parseResponse

This commit is contained in:
runzexia 2018-06-22 13:17:27 +08:00
parent d7977bd0a8
commit 31a5d47787
1 changed files with 7 additions and 7 deletions

View File

@ -71,6 +71,10 @@ func (u *Unpacker) parseResponse() error {
if err != nil {
return err
}
if !u.output.IsValid() {
return fmt.Errorf("API Gateway output format error")
}
}
}
@ -78,16 +82,10 @@ 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 {
@ -96,6 +94,8 @@ func (u *Unpacker) parseError() error {
RetCode: int(retCodeValue.Elem().Int()),
Message: messageValue.Elem().String(),
}
} else {
return fmt.Errorf("can not get retcode/message")
}
return nil