fix: 在 handler 中检查错误,不再静默丢弃
This commit is contained in:
+14
-4
@@ -58,7 +58,10 @@ func (h *GenerateHandler) Generate(c *gin.Context) {
|
||||
}
|
||||
|
||||
sendEvent := func(event string, data interface{}) {
|
||||
jsonData, _ := json.Marshal(data)
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
jsonData = []byte(`{"error":"failed to marshal event data"}`)
|
||||
}
|
||||
fmt.Fprintf(c.Writer, "event: %s\ndata: %s\n\n", event, jsonData)
|
||||
flusher.Flush()
|
||||
}
|
||||
@@ -74,7 +77,14 @@ func (h *GenerateHandler) Generate(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Save analysis to DB
|
||||
resultJSON, _ := json.Marshal(pr)
|
||||
h.db.Exec(`INSERT INTO analyses (repo_id, type, base_ref, head_ref, result) VALUES (?, 'pr_description', ?, ?, ?)`,
|
||||
id, req.Base, req.Head, string(resultJSON))
|
||||
resultJSON, err := json.Marshal(pr)
|
||||
if err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": "marshal result: " + err.Error()})
|
||||
return
|
||||
}
|
||||
if _, err := h.db.Exec(`INSERT INTO analyses (repo_id, type, base_ref, head_ref, result) VALUES (?, 'pr_description', ?, ?, ?)`,
|
||||
id, req.Base, req.Head, string(resultJSON)); err != nil {
|
||||
sendEvent("error", map[string]interface{}{"message": "save analysis: " + err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user