use access json header / extend error message parsing

pull/89/head
bakito 3 years ago
parent 1eba478d10
commit dcc18c0bf3
No known key found for this signature in database
GPG Key ID: FAF93C1C384DD6B4

1
.gitignore vendored

@ -3,4 +3,5 @@
*.out
_*.md
.vscode
.idea
cmd

@ -9,6 +9,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/url"
"strings"
@ -64,15 +65,16 @@ func (c *wrapper) do(ctx context.Context, method, path string, in, out interface
req := &scm.Request{
Method: method,
Path: path,
Header: map[string][]string{
"Accept": {"application/json"},
},
}
// if we are posting or putting data, we need to
// write it to the body of the request.
if in != nil {
buf := new(bytes.Buffer)
json.NewEncoder(buf).Encode(in)
req.Header = map[string][]string{
"Content-Type": {"application/json"},
}
req.Header["Content-Type"] = []string{"application/json"}
req.Body = buf
}
@ -121,7 +123,9 @@ type pagination struct {
// Error represents a Stash error.
type Error struct {
Errors []struct {
Message string `json:"message"`
Status int `json:"status-code"`
Errors []struct {
Message string `json:"message"`
ExceptionName string `json:"exceptionName"`
CurrentVersion int `json:"currentVersion"`
@ -131,6 +135,9 @@ type Error struct {
func (e *Error) Error() string {
if len(e.Errors) == 0 {
if len(e.Message) > 0 {
return fmt.Sprintf("bitbucket: status: %d message: %s", e.Status, e.Message)
}
return "bitbucket: undefined error"
}
return e.Errors[0].Message

Loading…
Cancel
Save