Page MenuHomePhabricator

Improve error localization in REST handlers
Closed, ResolvedPublic

Description

REST handlers currently often use unlocalized error messages when return error responses in the 4xx range. They should use localized errors instead. This means constructing a LocalizedHttpException instead of a plain HttpException, and adding new translation keys to en.json and qqq.json in the i18n directory.

This search provides a quick survey of code that throws a plain HttpException: https://codesearch.wmcloud.org/search/?q=new%20HttpException

Note: Unlocalized messages are acceptable in the 5xx range, because clients should rarely see them.

Event Timeline

Note: Unlocalized messages are acceptable in the 5xx range, because clients should rarely see them.

If it's a user-facing message, then I think it must be localized, even if you want to report a 5xx HTTP code together with it. API clients will commonly present the error messages directly to the user, who may speak any language (at least they do with the MediaWiki action API, but I hope the convention persists with the REST API too).

If it's not a user-facing message (in other words: if the exception should never happen in production, and indicates a bug in our code), then it doesn't have to be localized, but in this case it should probably just be a generic unchecked exception of some kind (e.g. LogicException), so that it gets logged to our error logs and can be investigated.

Change 1008458 had a related patch set uploaded (by WQuarshie; author: WQuarshie):

[mediawiki/core@master] Improve error localization in REST handlers

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

Change 1008522 had a related patch set uploaded (by WQuarshie; author: WQuarshie):

[mediawiki/extensions/ReadingLists@master] Improve error localization in REST handlers

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

Change 1008458 merged by jenkins-bot:

[mediawiki/core@master] Improve error localization in REST handlers

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

Change 1008522 merged by jenkins-bot:

[mediawiki/extensions/ReadingLists@master] Improve error localization in REST handlers

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

Change #1015427 had a related patch set uploaded (by WQuarshie; author: WQuarshie):

[mediawiki/core@master] Improve error localization in REST handlers

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

FJoseph-WMF changed the task status from Open to In Progress.Apr 5 2024, 2:42 PM

Change #1015427 merged by jenkins-bot:

[mediawiki/core@master] Use LocalizedHttpException for remaining errors in REST handlers

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

Change #1025808 had a related patch set uploaded (by Isabelle Hurbain-Palatin; author: Isabelle Hurbain-Palatin):

[mediawiki/services/parsoid@master] Fix response check on Parsoid API error

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

Change #1025808 merged by jenkins-bot:

[mediawiki/services/parsoid@master] Fix response check on Parsoid API error

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

Change #1026561 had a related patch set uploaded (by WQuarshie; author: WQuarshie):

[mediawiki/core@master] Remove fullstops from error messages

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

Change #1026561 merged by jenkins-bot:

[mediawiki/core@master] Remove fullstops from error messages

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

BPirkle moved this task from In Progress to Done on the MW-Interfaces-Team board.

Change #1028554 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.20.0-a4

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

Change #1028554 merged by jenkins-bot:

[mediawiki/vendor@master] Bump wikimedia/parsoid to 0.20.0-a4

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