usgpo / api

services to access govinfo content and metadata
https://api.govinfo.gov
Other
182 stars 58 forks source link

Return 404 response for related service specific relationship where no related documents are available #158

Closed jonquandt closed 3 months ago

jonquandt commented 6 months ago

Requests to the API related service for a relationship to a specific accessid for a specific collection are returning the standard error message, but with a 200 HTTP status code instead of the appropriate 404 code.

For example, https://api.govinfo.gov/related/BILLSTATUS-118hr99999/BILLS?api_key=DEMO_KEY will return the correct error message, but it will return with a 200 error code. This should return 404 instead.

{
  "message": "There are either no related documents available for this resource at this time, or the relationship has not been defined yet. If you know there are related documents that should be available for this resource,check again later or please check the https://www.github.com/usgpo/api repository to see the status of available relationships and submit an issue request as appropriate.",
  "relatedId": "BILLSTATUS-118hr99999"
}
ryparker commented 6 months ago

Would be nice to also have the packages API return 404 when the resource does not exist.

e.g.

curl 'https://api.govinfo.gov/packages/BILLSTATUS-118hr8386/xml?api_key=<API_KEY>&format=json'

Response: 400

{
  "message": "The requested resource does not exist."
}
jonquandt commented 6 months ago

@ryparker - we can look at improving the error reporting for that situation as well, though the format parameter is not one that's supported by the GovInfo API - your request is asking for a BILLSTATUS package using the xml endpoint (/packages/BILLSTATUS-118hr8386/xml) and then using a parameter that is invalid/not expected.

BILLSTATUS packages are currently not available in JSON. You can see what formats are available in the /summary endpoint.

https://api.govinfo.gov/packages/BILLSTATUS-118hr8386/summary?api_key=DEMO_KEY

As part of our effort to make the BILLSUM collection available via the API, I realized that our BILLSTATUS and ECFR collections are returning /bulkdata links instead of /packages/packageId/xml links. For consistency, we will be updating that in the future so that things are more consistent with other collections.

See https://github.com/usgpo/api/issues/159

ryparker commented 6 months ago

though the format parameter is not one that's supported by the GovInfo API

oops! Removing that param resolved the resource as expected.

As part of our effort to make the BILLSUM collection available via the API, I realized that our BILLSTATUS and ECFR collections are returning /bulkdata links instead of /packages/packageId/xml links. For consistency, we will be updating that in the future so that things are more consistent with other collections.

Excellent! Thanks for prioritizing this.

jonquandt commented 3 months ago

@ryparker - FYI - the error code issue is not resolved, BILLSUM is now available via the API, and BILLSTATUS xmlLinks are now using the standard API pattern.