API: Handle exceptions from ApiBeforeMain hook in a user-friendly manner
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 6 Mar 2014 14:37:26 +0000 (09:37 -0500)
committerOri.livneh <ori@wikimedia.org>
Wed, 12 Mar 2014 19:26:20 +0000 (19:26 +0000)
commit1d79bd6036e3e004669c625b91023d755fc4f38b
tree98ba5e599946d7f2d502f9f90bfaf7e9c0de2caf
parentceccc158847c173d5a1c2b388334268222832e4a
API: Handle exceptions from ApiBeforeMain hook in a user-friendly manner

The immediate impetus behind this change is this series of events:

1. CirrusSearch hooks ApiBeforeMain to handle some setup that requires
   the User object.
2. So User is loaded from the session.
3. OAuth checks the headers as part of loading User.
4. OAuth sees that the headers are invalid, and since it was called from
   the API it throws a UsageException, expecting the API to catch it and
   return an appropriate response to the client.
5. But nothing does so, leading to an unhelpful "Internal Error" page
   being returned to the client.

We can do better than that.

Bug: 62312
Change-Id: Ib5735661eec6ebe57eaa69c67b399e703cc90fc4
api.php
includes/api/ApiMain.php