Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Adding error reason to message, when JWT token signing failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
lpusok committed Dec 7, 2020
1 parent 522bf4e commit 60d5b16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions appstoreconnect/appstoreconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c *Client) NewRequest(method, endpoint string, body interface{}) (*http.Re
endpoint = apiVersion + "/" + endpoint
u, err := c.BaseURL.Parse(endpoint)
if err != nil {
return nil, err
return nil, fmt.Errorf("parsing endpoint failed, %v", err)
}

var buf io.ReadWriter
Expand All @@ -111,13 +111,13 @@ func (c *Client) NewRequest(method, endpoint string, body interface{}) (*http.Re
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
if err := enc.Encode(body); err != nil {
return nil, err
return nil, fmt.Errorf("encoding body failed, %v", err)
}
}

req, err := http.NewRequest(method, u.String(), buf)
if err != nil {
return nil, err
return nil, fmt.Errorf("preparing request failed, %v", err)
}

if body != nil {
Expand All @@ -127,7 +127,7 @@ func (c *Client) NewRequest(method, endpoint string, body interface{}) (*http.Re
if _, ok := c.client.(*http.Client); ok {
signedToken, err := c.ensureSignedToken()
if err != nil {
return nil, err
return nil, fmt.Errorf("ensuring JWT token failed, %v", err)
}
req.Header.Set("Authorization", "Bearer "+signedToken)
}
Expand Down
3 changes: 2 additions & 1 deletion appstoreconnect/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"time"

jwt "github.com/dgrijalva/jwt-go"
Expand All @@ -18,7 +19,7 @@ func signToken(token *jwt.Token, privateKeyContent []byte) (string, error) {
}
key, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
return "", err
return "", fmt.Errorf("failed to sign JWT token, private key format is invalid: %v", err)
}

privateKey, ok := key.(*ecdsa.PrivateKey)
Expand Down

0 comments on commit 60d5b16

Please sign in to comment.