Skip to content

Commit

Permalink
fix panic (#69)
Browse files Browse the repository at this point in the history
如果:

```
Error *Error   `json:"error"`
```

而服务器没有返回 error 字段,会在执行:

```
if resp.Error.Code > 0 {
```

时报错:

```
panic: runtime error: invalid memory address or nil pointer dereference
```
  • Loading branch information
leonardoli2022 authored Oct 24, 2022
1 parent 1e2aa3f commit 55bc2f8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion address.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func ReadAddress(ctx context.Context, addressId, uid, sid, sessionKey string) (*

var resp struct {
Data *Address `json:"data"`
Error *Error `json:"error"`
Error Error `json:"error"`
}
err = json.Unmarshal(body, &resp)
if err != nil {
Expand Down

0 comments on commit 55bc2f8

Please sign in to comment.