From a8d7cf35c55c833b1b8e281f972d62e4ec024f65 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 17 Nov 2024 17:28:44 +0100 Subject: [PATCH] dump response body in error response --- tcl_stop.go | 11 ++++++++--- velov.go | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tcl_stop.go b/tcl_stop.go index ceae384..bb840f9 100644 --- a/tcl_stop.go +++ b/tcl_stop.go @@ -58,15 +58,19 @@ func getPassages(ctx context.Context, config GrandLyonConfig, now func() time.Ti client = &http.Client{} } - var tclPassages TCLPassages + var ( + tclPassages TCLPassages + errResponse string + ) err := requests.URL("https://download.data.grandlyon.com/ws/rdata/tcl_sytral.tclpassagearret/all.json?maxfeatures=-1"). Client(client). + AddValidator(requests.ValidatorHandler(requests.DefaultValidator, requests.ToString(&errResponse))). BasicAuth(config.Username, config.Password). ToJSON(&tclPassages). Fetch(ctx) if err != nil { - return nil, fmt.Errorf("fetching passages: %w", err) + return nil, fmt.Errorf("fetching passages: %w (%v)", err, errResponse) } type passageKey struct { @@ -94,11 +98,12 @@ func getPassages(ctx context.Context, config GrandLyonConfig, now func() time.Ti err = requests.URL("https://download.data.grandlyon.com/ws/rdata/tcl_sytral.tclarret/all.json?maxfeatures=-1"). Client(client). + AddValidator(requests.ValidatorHandler(requests.DefaultValidator, requests.ToString(&errResponse))). BasicAuth(config.Username, config.Password). ToJSON(&tclStops). Fetch(ctx) if err != nil { - return nil, fmt.Errorf("fetching stops: %w", err) + return nil, fmt.Errorf("fetching stops: %w (%v)", err, errResponse) } updated := 0 diff --git a/velov.go b/velov.go index 7a49b4f..f77ebb5 100644 --- a/velov.go +++ b/velov.go @@ -31,13 +31,18 @@ type stationInfo struct { var errStationNotFound = errors.New("station not found") func getStation(ctx context.Context, client *http.Client, stationID int) (*Station, error) { - var info stationInfo + var ( + info stationInfo + errResponse string + ) + err := requests.URL("https://data.grandlyon.com/fr/datapusher/ws/rdata/jcd_jcdecaux.jcdvelov/all.json?maxfeatures=-1&start=1"). + AddValidator(requests.ValidatorHandler(requests.DefaultValidator, requests.ToString(&errResponse))). Client(client). ToJSON(&info). Fetch(ctx) if err != nil { - return nil, fmt.Errorf("querying station info: %w", err) + return nil, fmt.Errorf("querying station info: %w (%v)", err, errResponse) } station := Station{}