Skip to content

POST /validate returns 500 instead of 400 when feedUrl is missing or field name is wrong #192

@jcpitre

Description

@jcpitre

Created by Copilot.

Description

When a POST request is made to /validate with an incorrect field name (e.g. url instead of feedUrl), or with a missing feedUrl field entirely, the API returns a 500 Internal Server Error instead of a meaningful 400 Bad Request.

Steps to reproduce

curl -X POST https://gbfs.api.mobilitydatabase.org/validate \
  -H "Content-Type: application/json" \
  -d '{"url":"https://gbfs.velobixi.com/gbfs/gbfs.json"}'

Expected behavior

{ "status": 400, "error": "Bad Request", "message": "feedUrl is required" }

Actual behavior

{ "status": 500, "error": "Internal Server Error", "path": "/validate" }

Root cause

In ValidateApiDelegateHandler.validatePost(), getFeedUrl() returns null when the field is absent or misnamed. This null is passed directly to loader.load(), which throws an uncaught exception that Spring converts to a 500.

Suggested fix

Add a null/blank check at the top of validatePost():

if (validatePostRequest.getFeedUrl() == null || validatePostRequest.getFeedUrl().isBlank()) {
    return ResponseEntity.badRequest().build();
}

Or preferably, annotate feedUrl with @NotBlank in ValidatePostRequest and add @Valid to the controller parameter — Spring will then return a 400 automatically with a descriptive message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions