From 910e379265a75967415bae535598a40d4f55d6e1 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 23 May 2018 16:57:21 +0800 Subject: [PATCH] fix webhook bug of response info is not displayed in UI (#4023) --- models/webhook.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/models/webhook.go b/models/webhook.go index 62db84f86..6f7554ba3 100644 --- a/models/webhook.go +++ b/models/webhook.go @@ -437,7 +437,14 @@ func (t *HookTask) AfterLoad() { t.RequestInfo = &HookRequest{} if err := json.Unmarshal([]byte(t.RequestContent), t.RequestInfo); err != nil { - log.Error(3, "Unmarshal[%d]: %v", t.ID, err) + log.Error(3, "Unmarshal RequestContent[%d]: %v", t.ID, err) + } + + if len(t.ResponseContent) > 0 { + t.ResponseInfo = &HookResponse{} + if err := json.Unmarshal([]byte(t.ResponseContent), t.ResponseInfo); err != nil { + log.Error(3, "Unmarshal ResponseContent[%d]: %v", t.ID, err) + } } } @@ -619,6 +626,10 @@ func (t *HookTask) deliver() { log.Trace("Hook delivery failed: %s", t.UUID) } + if err := UpdateHookTask(t); err != nil { + log.Error(4, "UpdateHookTask [%d]: %v", t.ID, err) + } + // Update webhook last delivery status. w, err := GetWebhookByID(t.HookID) if err != nil { @@ -671,10 +682,6 @@ func DeliverHooks() { // Update hook task status. for _, t := range tasks { t.deliver() - - if err := UpdateHookTask(t); err != nil { - log.Error(4, "UpdateHookTask [%d]: %v", t.ID, err) - } } // Start listening on new hook requests. @@ -695,10 +702,6 @@ func DeliverHooks() { } for _, t := range tasks { t.deliver() - if err := UpdateHookTask(t); err != nil { - log.Error(4, "UpdateHookTask [%d]: %v", t.ID, err) - continue - } } } }