microsoft / planetary-computer-apis

Planetary Computer APIs
MIT License
105 stars 26 forks source link

Search errors messages should be JSON, not plain text #151

Open gadomski opened 1 year ago

gadomski commented 1 year ago

Describe the bug As described https://github.com/stac-utils/stac-fastapi/issues/463#issuecomment-1412811704, the error response from the /search endpoint (and others) should be JSON. It looks like the Planetary Computer is opting-in to plaintext responses: https://github.com/microsoft/planetary-computer-apis/blob/95190c56b70a5c824af25b68fba7d0d45d255451/pcstac/pcstac/main.py#L138-L142

Is there a reason to not return JSON here?

To reproduce

$ curl -i --json @query.json https://planetarycomputer.microsoft.com/api/stac/v1/search
HTTP/2 400 
content-length: 124
content-type: text/plain; charset=utf-8
strict-transport-security: max-age=15724800; includeSubDomains
access-control-allow-origin: *
access-control-allow-credentials: true
x-cache: CONFIG_NOCACHE
x-azure-ref: 0UNLaYwAAAADvTHj17Z8kSZvAjSBV+G7DV1NURURHRTA4MTUAOTI3YWJmYTYtMTlmNi00YWYxLWEwOWQtYzk1OWQ5YTFlNjQ0
date: Wed, 01 Feb 2023 20:57:52 GMT

1 validation error for Request
body -> intersects
  intersects and bbox parameters are mutually exclusive (type=value_error)

Expected behavior

$ curl -si --json @query.json http://localhost:8080/search
HTTP/1.1 400 Bad Request
date: Thu, 02 Feb 2023 14:32:46 GMT
server: uvicorn
content-length: 176
content-type: application/json

{"code":"RequestValidationError","description":"1 validation error for Request\nbody -> intersects\n  intersects and bbox parameters are mutually exclusive (type=value_error)"}
mmcfarland commented 1 year ago

IIRC, this was added after some feedback around text vs json error responses. However, if it's invalid against the stac-api spec we should remove. I'll add an internal issue to track.