Skip to content

Commit

Permalink
add logs in twilio handler
Browse files Browse the repository at this point in the history
  • Loading branch information
TuhinNair committed Dec 8, 2020
1 parent 1709f5a commit fac4566
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/web/twilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,29 @@ func (tr *twilioResponse) respond(twilioClient *twilio.Client) error {

func (tb *TwilioBot) handleWhatsapp(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
log.Println("Method Not Allowed")
w.Header().Set("Allow", "POST")
http.Error(w, http.StatusText(405), 405)
return
}

err := tb.validator.validateRequest(r)
if err != nil {
log.Println("Twilio not authenticated")
http.Error(w, http.StatusText(401), 401)
return
}

twilioRequestData, err := tb.parseRequest(r)
if err != nil {
log.Println("Malformed request")
http.Error(w, http.StatusText(400), 400)
return
}

err = tb.respond(twilioRequestData)
if err != nil {
log.Println("Unable to respond")
http.Error(w, http.StatusText(500), 500)
} else {
w.WriteHeader(200)
Expand Down

0 comments on commit fac4566

Please sign in to comment.