Skip to content

Commit

Permalink
Merge pull request #89 from bakito/master
Browse files Browse the repository at this point in the history
use access json header / extend error message parsing for stash
  • Loading branch information
eoinmcafee00 authored Jun 29, 2021
2 parents 789674c + dcc18c0 commit 3a08005
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.out
_*.md
.vscode
.idea
cmd
15 changes: 11 additions & 4 deletions scm/driver/stash/stash.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/url"
"strings"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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"`
Expand All @@ -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
Expand Down

0 comments on commit 3a08005

Please sign in to comment.