API talk:Extensions
Make "this is about modules" more obvious [edit]
Today a developer tried to find this, to learn about writing API modules, and didn't see it. How can we make it more discoverable? Sumana Harihareswara, Wikimedia Foundation Volunteer Development Coordinator 01:27, 9 February 2012 (UTC)
How should an API return errors? [edit]
This doesn't explain how extensions should handle error cases in their API, it would be very helpful if it did. API:Errors and warnings says clients of extensions will get an error with code and info fields, but how do extensions return these?
ApiBase implements
- setWarning() function, seems to stack up warnings
- a dieUsage that seems relevant.
E.g. includes/api/ApiEmailUser.php calls $this->dieUsageMsg( ) for API failures while returning result of 'Success' or 'Failure' when it interprets a MW Status object. The function signature is
public function dieUsage( $description, $errorCode, $httpRespCode = 0, $extradata = null );
In ApiBase there's a getPossibleErrors() function and some API providers return an array of 'code', 'info' pairs, is that related?
Also is there any namespacing of errorcode and info? Localization? Presumably code calling API's should show appropriately localized messages to the user according to the error's code
$this->dieUsageMsg( wfMsg( 'my-error-string' ), my-error-code );
and the ; Are there default localized messages for the the predefined API error codes? -- User:S Page (WMF) 23:20, 24 October 2012 (UTC)
- I added a bit of info here. Leucosticte (talk) 01:11, 25 October 2012 (UTC)
- Definitely helps, thanks on behalf of all developers! -- S Page (WMF) (talk) 06:17, 25 October 2012 (UTC)