@@ -15,10 +15,17 @@ import (
1515 "github.com/PuerkitoBio/goquery"
1616)
1717
18+ // ViewJobError is an error happened during and after a view is requesting.
19+ type ViewJobError struct {
20+ Name string `json:"name"`
21+ Message string `json:"message"`
22+ }
23+
1824type HypernovaResult struct {
1925 Success bool
2026 Html string
2127 Name string
28+ Error ViewJobError
2229}
2330
2431type HypernovaResponse struct {
@@ -77,6 +84,10 @@ func modifyBody(html string) string {
7784 batch [uuid ]["data" ] = data
7885 })
7986
87+ if len (batch ) == 0 {
88+ return html
89+ }
90+
8091 b , encodeErr := json .Marshal (batch )
8192
8293 if encodeErr != nil {
@@ -88,7 +99,8 @@ func modifyBody(html string) string {
8899 resp , reqErr := http .Post (os .Getenv ("HYPERNOVA_BATCH" ), "application/json" , strings .NewReader (payload ))
89100
90101 if reqErr != nil {
91- log .Fatal (reqErr )
102+ log .Println (reqErr )
103+ return html
92104 }
93105
94106 defer resp .Body .Close ()
@@ -104,14 +116,16 @@ func modifyBody(html string) string {
104116 json .Unmarshal (body , & hypernovaResponse )
105117
106118 for uuid , result := range hypernovaResponse .Results {
119+ divQuery := createQuery ("div" , uuid , result .Name )
120+
107121 if ! result .Success {
108- break
122+ doc .Find (divQuery ).PrependHtml ("<!-- Proxy Error: " + result .Error .Name + " -->" )
123+ continue
109124 }
110125
111126 scriptQuery := createQuery ("script" , uuid , result .Name )
112127 doc .Find (scriptQuery ).Remove ()
113128
114- divQuery := createQuery ("div" , uuid , result .Name )
115129 doc .Find (divQuery ).ReplaceWithHtml (result .Html )
116130 }
117131
0 commit comments