Skip to content

Commit

Permalink
👌 Sensible annotations save/gtg endpoint defaults. Return the full ur…
Browse files Browse the repository at this point in the history
…l in case of PUT failure.
  • Loading branch information
peteclark-ft committed Oct 5, 2017
1 parent baec00e commit f42b06a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions annotations/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func (p *pacWriter) Write(uuid string, tid string, body map[string]interface{})
return nil, err
}

req, err := http.NewRequest("PUT", fmt.Sprintf(p.saveEndpoint, uuid), bytes.NewReader(bodyJSON))
uri := fmt.Sprintf(p.saveEndpoint, uuid)
req, err := http.NewRequest("PUT", uri, bytes.NewReader(bodyJSON))
if err != nil {
return nil, err
}
Expand All @@ -48,7 +49,7 @@ func (p *pacWriter) Write(uuid string, tid string, body map[string]interface{})
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("Save to %v returned a %v status code", p.saveEndpoint, resp.StatusCode)
return nil, fmt.Errorf("Save to %v returned a %v status code", uri, resp.StatusCode)
}

dec := json.NewDecoder(resp.Body)
Expand Down
2 changes: 1 addition & 1 deletion annotations/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestWriteResponseFails(t *testing.T) {

body := make(map[string]interface{})
_, err := writer.Write(uuid, "tid_"+uuid, body)
assert.EqualError(t, err, fmt.Sprintf("Save to %v/drafts/content/%%v/annotations returned a 503 status code", server.URL))
assert.EqualError(t, err, fmt.Sprintf("Save to %v/drafts/content/%v/annotations returned a 503 status code", server.URL, uuid))
}

func TestWriteResponseInvalidJSON(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ func main() {
saveEndpoint := app.String(cli.StringOpt{
Name: "annotations-save-endpoint",
Desc: "Endpoint to save annotations to PAC",
Value: "http://draft-annotations-api:8080/drafts/content/%v/annotations",
EnvVar: "ANNOTATIONS_SAVE_ENDPOINT",
})

saveGTGEndpoint := app.String(cli.StringOpt{
Name: "annotations-save-gtg-endpoint",
Desc: "GTG Endpoint for the service which saves PAC annotations (usually draft-annotations-api)",
Value: "http://draft-annotations-api:8080/__gtg",
EnvVar: "ANNOTATIONS_SAVE_GTG_ENDPOINT",
})

Expand Down

0 comments on commit f42b06a

Please sign in to comment.