From 29156678957f19aa018eefb8baf2a2a135283828 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 22 Sep 2018 23:23:02 +0200 Subject: [PATCH] Rearrange status checks in UpdatePost --- post.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/post.go b/post.go index 4e1f11f..977918e 100644 --- a/post.go +++ b/post.go @@ -148,14 +148,15 @@ func (c *Client) UpdatePost(sp *PostParams) (*Post, error) { } status := env.Code - if status == http.StatusOK { - return p, nil - } else if c.isNotLoggedIn(status) { - return nil, fmt.Errorf("Not authenticated.") - } else if status == http.StatusBadRequest { - return nil, fmt.Errorf("Bad request: %s", env.ErrorMessage) + if status != http.StatusOK { + if c.isNotLoggedIn(status) { + return nil, fmt.Errorf("Not authenticated.") + } else if status == http.StatusBadRequest { + return nil, fmt.Errorf("Bad request: %s", env.ErrorMessage) + } + return nil, fmt.Errorf("Problem getting post: %d. %v\n", status, err) } - return nil, fmt.Errorf("Problem getting post: %d. %v\n", status, err) + return p, nil } // DeletePost permanently deletes a published post. See