dump response body in error response

This commit is contained in:
Gabriel Augendre 2024-11-17 17:28:44 +01:00
parent 95e80134ee
commit a8d7cf35c5
2 changed files with 15 additions and 5 deletions

View file

@ -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

View file

@ -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{}