* Adding debugging for webhook

* Fixing build error

* Moving error down
Этот коммит содержится в:
Corey Hulen
2017-08-18 15:58:26 -07:00
коммит произвёл GitHub
родитель 2b3f7d0bc3
Коммит 4a8afebcdb
3 изменённых файлов: 13 добавлений и 8 удалений

Просмотреть файл

@@ -476,7 +476,12 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
parsedRequest := model.IncomingWebhookRequestFromJson(payload)
parsedRequest, decodeError := model.IncomingWebhookRequestFromJson(payload)
if decodeError != nil {
c.Err = decodeError
return
}
err := app.HandleIncomingWebhook(id, parsedRequest)
if err != nil {

Просмотреть файл

@@ -193,7 +193,7 @@ func decodeIncomingWebhookRequest(by []byte) (*IncomingWebhookRequest, error) {
}
}
func IncomingWebhookRequestFromJson(data io.Reader) *IncomingWebhookRequest {
func IncomingWebhookRequestFromJson(data io.Reader) (*IncomingWebhookRequest, *AppError) {
buf := new(bytes.Buffer)
buf.ReadFrom(data)
by := buf.Bytes()
@@ -204,12 +204,12 @@ func IncomingWebhookRequestFromJson(data io.Reader) *IncomingWebhookRequest {
if err != nil {
o, err = decodeIncomingWebhookRequest(escapeControlCharsFromPayload(by))
if err != nil {
return nil
return nil, NewAppError("IncomingWebhookRequestFromJson", "Unable to parse incoming data", nil, err.Error(), http.StatusBadRequest)
}
}
o.Text = ExpandAnnouncement(o.Text)
o.Attachments = ProcessSlackAttachments(o.Attachments)
return o
return o, nil
}

Просмотреть файл

@@ -108,7 +108,7 @@ func TestIncomingWebhookRequestFromJson_Announcements(t *testing.T) {
// simple payload
payload := `{"text": "` + text + `"}`
data := strings.NewReader(payload)
iwr := IncomingWebhookRequestFromJson(data)
iwr, _ := IncomingWebhookRequestFromJson(data)
if iwr == nil {
t.Fatal("IncomingWebhookRequest should not be nil")
@@ -136,7 +136,7 @@ func TestIncomingWebhookRequestFromJson_Announcements(t *testing.T) {
}`
data = strings.NewReader(payload)
iwr = IncomingWebhookRequestFromJson(data)
iwr, _ = IncomingWebhookRequestFromJson(data)
if iwr == nil {
t.Fatal("IncomingWebhookRequest should not be nil")
@@ -213,7 +213,7 @@ func TestIncomingWebhookRequestFromJson(t *testing.T) {
// try to create an IncomingWebhookRequest from the payload
data := strings.NewReader(payload)
iwr := IncomingWebhookRequestFromJson(data)
iwr, _ := IncomingWebhookRequestFromJson(data)
// After it has been decoded, the JSON string won't contain the escape char anymore
expected := strings.Replace(text, `\"`, `"`, -1)
@@ -233,7 +233,7 @@ func TestIncomingWebhookRequestFromJson(t *testing.T) {
func TestIncomingWebhookNullArrayItems(t *testing.T) {
payload := `{"attachments":[{"fields":[{"title":"foo","value":"bar","short":true}, null]}, null]}`
iwr := IncomingWebhookRequestFromJson(strings.NewReader(payload))
iwr, _ := IncomingWebhookRequestFromJson(strings.NewReader(payload))
if iwr == nil {
t.Fatal("IncomingWebhookRequest should not be nil")
}