Fix server error message, go fmt

This commit is contained in:
Aaron Lindsay 2013-03-18 07:17:44 -04:00
parent ad8156210f
commit 3a166dbc9a
4 changed files with 15 additions and 8 deletions

View File

@ -110,7 +110,6 @@ func GetEvents(globals AsinkGlobals, events chan *asink.Event) {
continue continue
} }
for _, event := range apistatus.Events { for _, event := range apistatus.Events {
if latestEvent != nil && event.Id != latestEvent.Id+1 { if latestEvent != nil && event.Id != latestEvent.Id+1 {
break break

View File

@ -128,6 +128,9 @@ func putEvents(w http.ResponseWriter, r *http.Request) {
for _, event := range events.Events { for _, event := range events.Events {
err = DatabaseAddEvent(db, event) err = DatabaseAddEvent(db, event)
if err != nil { if err != nil {
//TODO should probably do this in a way that the caller knows how many of these have failed and doesn't re-try sending ones that succeeded
//i.e. add this to the return codes or something
//OR put all the DatabaseAddEvent's inside a SQL transaction, and rollback on any failure
error_message = err.Error() error_message = err.Error()
return return
} }
@ -154,6 +157,11 @@ func eventHandler(w http.ResponseWriter, r *http.Request) {
} else if r.Method == "POST" { } else if r.Method == "POST" {
putEvents(w, r) putEvents(w, r)
} else { } else {
fmt.Fprintf(w, "You f-ed up.") apiresponse := asink.APIResponse{
Status: asink.ERROR,
Explanation: "Invalid HTTP method - only GET and POST are supported on this endpoint.",
}
b, _ := json.Marshal(apiresponse)
w.Write(b)
} }
} }