Skip to content

Commit 85f3897

Browse files
committed
Fix issue with getting a 500 and setting a endslash
1 parent 3545b09 commit 85f3897

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

client.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,30 @@ func (c *Client) newRequest(method, endpoint string, in interface{}) (*http.Requ
135135
return req, nil
136136
}
137137

138+
func (c *Client) rawRequest(method, endpoint string, in interface{}) (*http.Request, error) {
139+
var bodyreader io.Reader
140+
141+
if in != nil {
142+
newbodyreader, err := c.encodeOrError(in)
143+
if err != nil {
144+
return nil, err
145+
}
146+
bodyreader = newbodyreader
147+
}
148+
149+
req, err := http.NewRequest(method, c.Endpoint+endpoint, bodyreader)
150+
if err != nil {
151+
return nil, err
152+
}
153+
154+
req.Header.Add("Content-Type", "application/json")
155+
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.AuthToken))
156+
req.Close = true
157+
158+
return req, nil
159+
160+
}
161+
138162
func (c *Client) doWithQuery(method string, endpoint string, out interface{}, in interface{}, query QueryArgs) error {
139163
request, err := c.newRequest(method, endpoint, in)
140164
if err != nil {
@@ -168,6 +192,15 @@ func (c *Client) doWithPagination(method, endpoint string, out, in interface{})
168192
return c.sendGetLink(request, out)
169193
}
170194

195+
//rawWithPagination is used when we need to get a raw URL vs a url we combine and comb with newrequest
196+
func (c *Client) rawWithPagination(method, endpoint string, out, in interface{}) (*Link, error) {
197+
request, err := c.rawRequest(method, endpoint, in)
198+
if err != nil {
199+
return nil, err
200+
}
201+
return c.sendGetLink(request, out)
202+
}
203+
171204
func (c *Client) fetchLink(r *http.Response) *Link {
172205
link := &Link{}
173206
if r.Header.Get("Link") != "" {

pagination.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ func NewLink(linkheader string) *Link {
4848
// GetPage will fetch a page via the Link object and decode it from out.
4949
// Should be used like `client.GetPage(link.Previous, make([]Organization, 0))`
5050
func (c *Client) GetPage(p Page, out interface{}) (*Link, error) {
51-
return c.doWithPagination("GET", strings.TrimPrefix(p.URL, c.Endpoint), out, nil)
51+
return c.rawWithPagination("GET", strings.TrimPrefix(p.URL, c.Endpoint), out, nil)
5252
}

0 commit comments

Comments
 (0)