Browse Source

Gracefully catch 401 error in Client.GetMe method

main
Matt Baer 1 year ago
parent
commit
c692cb4988
1 changed files with 6 additions and 0 deletions
  1. +6
    -0
      user.go

+ 6
- 0
user.go View File

@@ -2,6 +2,7 @@ package writeas

import (
"fmt"
"net/http"
"time"
)

@@ -52,6 +53,11 @@ func (c *Client) GetMe(verbose bool) (*User, error) {
return nil, err
}

status := env.Code
if status == http.StatusUnauthorized {
return nil, fmt.Errorf("invalid or expired token")
}

var u *User
var ok bool
if u, ok = env.Data.(*User); !ok {


Loading…
Cancel
Save