return empty passage instead of 404

This commit is contained in:
Gabriel Augendre 2024-10-21 22:43:09 +02:00
parent 4a906473de
commit 95e80134ee
3 changed files with 0 additions and 20 deletions

View file

@ -54,11 +54,6 @@ func addRoutes(api huma.API, glConfig GrandLyonConfig, now func() time.Time) {
StopID int `path:"stopID" doc:"Stop id to monitor. Can be obtained using https://data.grandlyon.com/portail/fr/jeux-de-donnees/points-arret-reseau-transports-commun-lyonnais/donnees"` StopID int `path:"stopID" doc:"Stop id to monitor. Can be obtained using https://data.grandlyon.com/portail/fr/jeux-de-donnees/points-arret-reseau-transports-commun-lyonnais/donnees"`
}) (*stopOutput, error) { }) (*stopOutput, error) {
passages, err := getPassages(ctx, glConfig, now, input.StopID) passages, err := getPassages(ctx, glConfig, now, input.StopID)
if errors.Is(err, errNoPassageFound) {
slog.ErrorContext(ctx, "passage not found", getRequestIDAttr(ctx))
return nil, huma.NewError(http.StatusNotFound, "no passage found")
}
if err != nil { if err != nil {
slog.ErrorContext(ctx, "error getting passages", "err", err, getRequestIDAttr(ctx)) slog.ErrorContext(ctx, "error getting passages", "err", err, getRequestIDAttr(ctx))
return nil, err return nil, err

View file

@ -47,11 +47,6 @@ func TestGetStop(t *testing.T) {
addRoutes(api, config, now) addRoutes(api, config, now)
t.Run("stop not found", func(t *testing.T) {
resp := api.Get("/tcl/stop/0")
assert.Equal(t, resp.Code, http.StatusNotFound)
})
t.Run("stop exists", func(t *testing.T) { t.Run("stop exists", func(t *testing.T) {
resp := api.Get("/tcl/stop/290") resp := api.Get("/tcl/stop/290")
assert.Equal(t, resp.Code, http.StatusOK) assert.Equal(t, resp.Code, http.StatusOK)
@ -101,9 +96,6 @@ func TestGetVelovStation(t *testing.T) {
transport.RegisterResponder(http.MethodGet, transport.RegisterResponder(http.MethodGet,
"https://data.grandlyon.com/fr/datapusher/ws/rdata/jcd_jcdecaux.jcdvelov/all.json?maxfeatures=-1&start=1", "https://data.grandlyon.com/fr/datapusher/ws/rdata/jcd_jcdecaux.jcdvelov/all.json?maxfeatures=-1&start=1",
httpmock.NewBytesResponder(http.StatusOK, httpmock.File("./testdata/station_info.json").Bytes())) httpmock.NewBytesResponder(http.StatusOK, httpmock.File("./testdata/station_info.json").Bytes()))
//transport.RegisterResponder(http.MethodGet,
// "https://download.data.grandlyon.com/files/rdata/jcd_jcdecaux.jcdvelov/station_status.json",
// httpmock.NewBytesResponder(http.StatusOK, httpmock.File("./testdata/station_status.json").Bytes()))
addRoutes(api, config, time.Now) addRoutes(api, config, time.Now)

View file

@ -2,7 +2,6 @@ package main
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"github.com/carlmjohnson/requests" "github.com/carlmjohnson/requests"
"net/http" "net/http"
@ -53,8 +52,6 @@ func (d delay) String() string {
} }
} }
var errNoPassageFound = errors.New("no passage found")
func getPassages(ctx context.Context, config GrandLyonConfig, now func() time.Time, stopID int) (*Passages, error) { func getPassages(ctx context.Context, config GrandLyonConfig, now func() time.Time, stopID int) (*Passages, error) {
client := config.Client client := config.Client
if client == nil { if client == nil {
@ -93,10 +90,6 @@ func getPassages(ctx context.Context, config GrandLyonConfig, now func() time.Ti
passages[key] = delays passages[key] = delays
} }
if len(passages) == 0 {
return nil, errNoPassageFound
}
var tclStops TCLStops var tclStops TCLStops
err = requests.URL("https://download.data.grandlyon.com/ws/rdata/tcl_sytral.tclarret/all.json?maxfeatures=-1"). err = requests.URL("https://download.data.grandlyon.com/ws/rdata/tcl_sytral.tclarret/all.json?maxfeatures=-1").