Page MenuHomePhabricator

🟦 Handle errors in GET /entities/items/{item_id}
Closed, ResolvedPublic5 Estimated Story Points

Description

See Gerrit patch 770444 for the error response specifications

code is a symbolic category of errors
message is a human readable error message

BDD
WHEN I request GET /entities/items/{item_id} with ID of item that does not exist
THEN I get 404 HTTP response
AND it contains a item-not-found code and a message "Could not find an item with the ID {item_id}"
AND a HTTP header Content-Language set to en

BDD
WHEN I request GET /entities/items/{item_id} with a text which is not an item ID
THEN I get 400 HTTP response
AND it contains a invalid-item-id code and a message "Not a valid item ID: {item_id}"
AND a HTTP header Content-Language set to en

BDD
WHEN I request GET /entities/items/{item_id} with a valid item ID
AND a generic server or database error occurs
THEN I get 500 HTTP response
AND it contains a unexpected-error code and a message "Unexpected Error"
AND a HTTP header Content-Language set to en

Not included in this story

  • internationalized/translated error message via Accept-Language HTTP header

Note:

  • using the built-in error mechanism from MediaWiki REST API is fine as long as the specification is met

Event Timeline

Silvan_WMDE set the point value for this task to 5.

Change 770444 had a related patch set uploaded (by WMDE-leszek; author: WMDE-leszek):

[mediawiki/extensions/Wikibase@master] REST: Added specs for GET /entities/items/item_id errors

https://gerrit.wikimedia.org/r/770444

Silvan_WMDE renamed this task from Handle incorrect input in GET /entities/items/{item_id} to Handle errors in GET /entities/items/{item_id}.Mar 14 2022, 1:27 PM

Task Breakdown Notes

T303914: 🟦 Create 404 error response for non existing item IDs in GET /entities/items/{item_id}

  • return null from WikibaseEntityLookupItemRevisionRetriever in case no entity revision can be found for a given ID
  • if item revision is null, then an error result (with isSuccessful() == false) will be returned from the GetItem use case
  • the RouteHandler will create an error response (set http status, code, message) based on the GetItemResult

T303918: 🟦 Create a 400 HTTP response for invalid item IDs

  • create a Validator on the "use case level" that will check the item ID from the request and return a ValidatioResult object
  • if the ValdationResult has violations, an error result (with isSuccessful() == false) will be returned from the GetItem use case
  • the RouteHandler will create an error response (set http status, code, message) based on the GetItemResult

T303915: 🟦 Create 500 error response on exceptions in GET /entities/items/{item_id}

  • catch exceptions in the use case and return an error result (with isSuccessful() == false)
  • the RouteHandler will create an error response (set http status, code, message) based on the GetItemResult
Ollie.Shotton_WMDE renamed this task from Handle errors in GET /entities/items/{item_id} to 🟦 Handle errors in GET /entities/items/{item_id}.Mar 16 2022, 8:47 AM

Change 771344 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/extensions/Wikibase@master] REST: Update GetItemResult for success and failure results

https://gerrit.wikimedia.org/r/771344

Change 771383 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/extensions/Wikibase@master] REST: GetItemJsonPresenter return a JSON string instead of a JSON encodable array

https://gerrit.wikimedia.org/r/771383

WMDE-leszek added a subscriber: Jakob_WMDE.

@Silvan_WMDE @Ollie.Shotton_WMDE @Jakob_WMDE note that I've changed the expected error code and messages based on a recent discussion.

Change 770444 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Added specs for GET /entities/items/item_id errors

https://gerrit.wikimedia.org/r/770444

Change 771344 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Update GetItemResult for success and failure

https://gerrit.wikimedia.org/r/771344

Change 771383 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: GetItemJsonPresenter to return JSON string

https://gerrit.wikimedia.org/r/771383

Works as expected, thank you!

I've discovered two glitches to (possibly) follow up on:

  1. item-not-found case's error message could use a colon. Was missing from the BDD desccription (was included in the OpenAPI specification however!) so not blocking this. Fixed in: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Wikibase/+/773552
  2. Potentially it would be intended to have a consistent code and message keys also used in the errors when no ID is provided, which is currently caught by the mediawiki rest api "framework". This has not be covered in the specification, so again, not a problem to consider this done. For example see: https://wikidata.beta.wmflabs.org/w/rest.php/wikibase/v0/entities/items/. I will create a dedicated task for it if I find it a necessary change.