Repository navigation
Standardize problem reporting envelopes and params - #1641
vishnums2k5 wants to merge 1 commit into
Conversation
Update problem reporting handlers for stops and trips to return standard JSON 500 error responses via serverErrorResponse rather than plain-text http.Error. Support both OpenAPI parameter casing (vehicleID, stopID) and legacy casing (vehicleId, stopId) in reportProblemWithTripHandler. Store omitted optional query strings as SQL NULL via nulls.NonEmptyString instead of empty strings with Valid=true.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
aaronbrethorst
left a comment
There was a problem hiding this comment.
Thanks @vishnums2k5! The switch to serverErrorResponse and storing omitted strings as NULL both look good. Java leaves these fields null when they're omitted, so this matches it. One thing needs to change before this can land.
Accepting vehicleID/stopID on report-problem-with-trip changes what we store compared with Java. ReportProblemWithTripAction only has setVehicleId/setStopId, and Struts matches parameter names case-sensitively, so production drops vehicleID= and stopID= without a word. You can see the same case sensitivity on a read endpoint: stops-for-location?maxCount=1 returns 1 stop, while maxcount=1 is ignored and returns 49. With this PR, a request that sends vehicleID=1_3521 stores the vehicle, and on Java it doesn't.
This could well be the right call. The js-sdk sends vehicleID/stopID because that's what openapi.yml says, so on Java those values get lost. But it's a deviation from Java, so it needs a maintainer decision and an Implementation Decisions entry first. The simplest way forward is to drop the casing fallback from this PR and open an issue proposing it. That also gets this PR back to one concern. Please also link an issue in the description and fill in the response comparison, since the 500 body changes from plain text to JSON.
- The new 500 text is "internal server error" with
version: 2. Java returns the exception message withversion: 1(DC-10). That's the same as every other maglev handler, so it's fine here.



Fixes #
What it does
Standardizes problem reporting error responses and query parameter parsing for both stop and trip endpoints:
http.Errorcalls withapi.serverErrorResponse(w, r, err)so failures return standard OneBusAway JSON error envelopes with properContent-Type: application/json,currentTime, andversionfields.vehicleID,stopID) and legacy casing (vehicleId,stopId) inreportProblemWithTripHandler.code,userComment,serviceDate,vehicleID,stopID,userVehicleNumber) as SQLNULLvianulls.NonEmptyStringrather than empty strings withValid: true.Root cause
reportProblemWithStopHandlerandreportProblemWithTripHandlerpreviously usedhttp.Error, which emitted plain-text responses without the standard OneBusAway envelope structure. Additionally,testdata/openapi.ymlspecifiesvehicleIDandstopIDas query parameters, whereas the handler only looked upvehicleIdandstopId. Lastly, empty strings were being converted tosql.NullString{Valid: true}vianulls.String(""), persisting empty strings rather than database NULL values.Testing
mainbefore this change:TestReportProblemWithStopDatabaseFailure: Returnedtext/plain500 without JSON body/version.TestReportProblemWithStopNullStorage: Failed assertion because omitted fields hadValid: true.TestReportProblemWithTripDatabaseFailure: Returnedtext/plain500 without JSON body/version.TestReportProblemWithTripOpenAPICasingAndNulls: ParametersvehicleIDandstopIDwere ignored, and omitted fields stored""instead ofNULL.go test -tags "sqlite_fts5 sqlite_math_functions" -v ./internal/restapi -run "TestReportProblemWith": PASSmake test: PASS (all packages)make test-pure: PASS (all packages)go vet(both CGO and purego): PASSResponse comparison (delete if no Java-served response changed)
Checklist
Ready-for-review requirement: Every box must be checked. If any statement is not true, keep the pull request as Draft.
mainand passes on this branch.gtfsdb/(sqlc-generated) ortestdata/openapi.yml(synced from upstream).r.Context()to DB/service calls, notcontext.Background().testdata/openapi.yml, or an issue asking for it is open on OneBusAway/sdk-config.Notes for reviewers (optional)
Both
vehicleID/stopID(OpenAPI) andvehicleId/stopId(legacy) are accepted to ensure backward compatibility with both official OpenAPI-generated SDKs and existing web clients.Summary by CodeRabbit
vehicleID/stopIDandvehicleId/stopIdparameter casing.