Skip to content

Fix/route agency db error#793

Open
FLASH2332 wants to merge 2 commits intoOneBusAway:mainfrom
FLASH2332:fix/route-agency-db-error
Open

Fix/route agency db error#793
FLASH2332 wants to merge 2 commits intoOneBusAway:mainfrom
FLASH2332:fix/route-agency-db-error

Conversation

@FLASH2332
Copy link
Copy Markdown
Contributor

Problem:
In routeHandler, the error returned by GetAgency was silently discarded:
goagency, err := api.GtfsManager.GtfsDB.Queries.GetAgency(ctx, agencyID)

if err == nil {
    // agency added to references
}
// any error is silently dropped

If this DB call failed for any reason — including context.Canceled or context.DeadlineExceeded — the handler would skip the agency reference and return a successful response with incomplete data.

Fix :
sql.ErrNoRows → agency reference is optional, skip silently and continue
Any other error → route through serverErrorResponse, which correctly handles context cancellation and deadline exceeded

Changes :
internal/restapi/route_handler.go — added explicit error handling for GetAgency

Closes #792

@fletcherw
Copy link
Copy Markdown

Hi Jayadev, nice work noticing this issue. When I query the public API with an agency ID that doesn't exist I get a NotFound error, so I think the maglev implementation of routes should do the same.

As part of this fix, you should also add a test for this behavior in route_handler_test.

curl https://api.pugetsound.onebusaway.org/api/where/route/2_100224.json\?key\=TEST
{"code":404,"currentTime":1774819186552,"text":"resource not found","version":2}%     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

route-handler: DB error fetching agency reference data is silently ignored

2 participants