Skip to content
This repository was archived by the owner on Mar 31, 2021. It is now read-only.

Commit

Permalink
feat: exiting with proper error code if post fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jones2026 committed Aug 31, 2019
1 parent 7cacb30 commit 1514211
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
"os"
)

var logFatalf = log.Fatalf

type flowMessage struct {
Event string `json:"event"`
Content string `json:"content"`
}

type inboxMessage struct {
Event string `json:"event"`
Event string `json:"event"`
Title string `json:"title"`
}

Expand All @@ -26,6 +28,9 @@ func postMessage(raw []byte, err error, flowURL string) {

resp, err := http.Post(flowURL, "application/json", bytes.NewReader(raw))
if resp != nil {
if resp.StatusCode != 202 {
logFatalf("Failed to post message, flowdock api returned: %s", resp.Status)
}
fmt.Println(resp.Status)
resp.Body.Close()
}
Expand All @@ -40,7 +45,7 @@ func main() {

flowToken := os.Getenv("PLUGIN_FLOW_TOKEN")
if flowToken == "" {
log.Fatalln("Missing flow token")
log.Fatalln("Missing setting: flow_token")
}
flowURL := apiURL + flowToken

Expand All @@ -55,16 +60,16 @@ func main() {
messageType := os.Getenv("PLUGIN_MESSAGE_TYPE")

if messageType == "activity" {
msg := inboxMessage {
Event: "activity",
msg := inboxMessage{
Event: "activity",
Title: message,
}

raw, err := json.Marshal(msg)

postMessage(raw, err, flowURL)
} else {
msg := flowMessage {
msg := flowMessage{
Event: "message",
Content: message,
}
Expand Down

0 comments on commit 1514211

Please sign in to comment.