mirror of
https://github.com/Crocmagnon/lyon-transports.git
synced 2024-12-21 11:31:51 +01:00
return empty passage instead of 404
This commit is contained in:
parent
4a906473de
commit
95e80134ee
3 changed files with 0 additions and 20 deletions
5
main.go
5
main.go
|
@ -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"`
|
||||
}) (*stopOutput, error) {
|
||||
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 {
|
||||
slog.ErrorContext(ctx, "error getting passages", "err", err, getRequestIDAttr(ctx))
|
||||
return nil, err
|
||||
|
|
|
@ -47,11 +47,6 @@ func TestGetStop(t *testing.T) {
|
|||
|
||||
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) {
|
||||
resp := api.Get("/tcl/stop/290")
|
||||
assert.Equal(t, resp.Code, http.StatusOK)
|
||||
|
@ -101,9 +96,6 @@ func TestGetVelovStation(t *testing.T) {
|
|||
transport.RegisterResponder(http.MethodGet,
|
||||
"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()))
|
||||
//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)
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"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) {
|
||||
client := config.Client
|
||||
if client == nil {
|
||||
|
@ -93,10 +90,6 @@ func getPassages(ctx context.Context, config GrandLyonConfig, now func() time.Ti
|
|||
passages[key] = delays
|
||||
}
|
||||
|
||||
if len(passages) == 0 {
|
||||
return nil, errNoPassageFound
|
||||
}
|
||||
|
||||
var tclStops TCLStops
|
||||
|
||||
err = requests.URL("https://download.data.grandlyon.com/ws/rdata/tcl_sytral.tclarret/all.json?maxfeatures=-1").
|
||||
|
|
Loading…
Reference in a new issue