From 13322edf37510b6d3bb68a853368fd1a0a67a105 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Mon, 20 Nov 2023 17:07:28 +0100 Subject: Gracefully handle NaN and Inf values (#21) --- modules/jsonprint/jsonprint.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'modules/jsonprint/jsonprint.go') diff --git a/modules/jsonprint/jsonprint.go b/modules/jsonprint/jsonprint.go index a4be5c9..c40a8b9 100644 --- a/modules/jsonprint/jsonprint.go +++ b/modules/jsonprint/jsonprint.go @@ -41,9 +41,11 @@ func (m *Module) ReceiveResponse(resp *flyscrape.Response) { o := output{ URL: resp.Request.URL, Data: resp.Data, - Error: resp.Error, Timestamp: time.Now(), } + if resp.Error != nil { + o.Error = resp.Error.Error() + } fmt.Print(flyscrape.Prettify(o, " ")) } @@ -57,7 +59,7 @@ func (m *Module) Finalize() { type output struct { URL string `json:"url,omitempty"` Data any `json:"data,omitempty"` - Error error `json:"error,omitempty"` + Error string `json:"error,omitempty"` Timestamp time.Time `json:"timestamp,omitempty"` } -- cgit v1.2.3