Merge branch 'master' into errors
This commit is contained in:
commit
6a9d276a4d
16
messenger.go
16
messenger.go
@ -283,25 +283,33 @@ func (m *Messenger) handle(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
err = xerrors.Errorf("could not decode response: %w", err)
|
err = xerrors.Errorf("could not decode response: %w", err)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
fmt.Fprintln(w, `{status: 'not ok'}`)
|
fmt.Println("could not decode response:", err)
|
||||||
|
respond(w, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if rec.Object != "page" {
|
if rec.Object != "page" {
|
||||||
fmt.Println("object is not page, undefined behaviour. Got", rec.Object)
|
fmt.Println("Object is not page, undefined behaviour. Got", rec.Object)
|
||||||
|
respond(w, http.StatusUnprocessableEntity)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.verify {
|
if m.verify {
|
||||||
if err := m.checkIntegrity(r); err != nil {
|
if err := m.checkIntegrity(r); err != nil {
|
||||||
fmt.Println("could not verify request:", err)
|
fmt.Println("could not verify request:", err)
|
||||||
fmt.Fprintln(w, `{status: 'not ok'}`)
|
respond(w, http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.dispatch(rec)
|
m.dispatch(rec)
|
||||||
|
|
||||||
fmt.Fprintln(w, `{status: 'ok'}`)
|
respond(w, http.StatusAccepted) // We do not return any meaningful response immediately so it should be 202
|
||||||
|
}
|
||||||
|
|
||||||
|
func respond(w http.ResponseWriter, code int) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
fmt.Fprintf(w, `{"code": %d, "status": "%s"}`, code, http.StatusText(code))
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkIntegrity checks the integrity of the requests received
|
// checkIntegrity checks the integrity of the requests received
|
||||||
|
Loading…
x
Reference in New Issue
Block a user