API:Errors and warnings

If somethueifhskjding goes wresuhfbnrwsedihukfjnwong in an APfekhrbfI request, an errrgsuhidfkjnvgliutdghbjor or a warning will be thrown (although the HTTP response will usually still be ). Warefsdjhhnvfjsdnings are thrown for non-fauykmjhregsdfvucntal conditions such as invalid parameters, whereas erroeuashifjaswdkjrs are only thrown for fatal conditions.

Warnings
Warsrjghfvuskjgvnings are grouped by the name of the rgudkf,jvhcdcgukjnmodule that caused them. Multiple warnings from the same module are seprsgfiukhjdxfcgliukdfjnarated by a newline. In the legacy erguohsfjgujrror formatting regdfolki,jdmtccgikdrjtdfmode (see below), which is the default, warrfkugjsdivgjmnings are output in the following format:

( will be replaced by  when  is used.)

When a non-legacy error formatting option is used, warnings are output in the same format as errors. E.g. with the format will be: ( will be replaced with   when    is used.)

Error formats
Since MediaWiki 1.29 errors are localizable, and available in multiple formats. An error (or warning) is expected to consist of a message, an error code (an arbitrary string, usually generated from the message key; see also below), and optional extra data (an associative array). An API response with errors will look like this:

The  key in the output above will be missing if there is no extra data to display.

The way the error message in the output above is returned to the client is controlled by the  API parameter. The various error formats available are:

For the formatting modes which involve message lookup (,  and  ) the API parameter   can be used to set the language (only needed when different from the content language) and   to set whether the MediaWiki: namespace can be used to override default error messages.

Error codes are also returned in the  response HTTP header, separated by commas when there are multiple errors.

For an example error response or to test your client's error handling, visit https://en.wikipedia.org/w/api.php?action=blah&errorformat=plaintext&format=jsonfm&formatversion=2

When  is not set (or set to  ), errors will be displayed in the legacy format instead.

Legacy format
In the legacy error format, there is always at most one error; additional ones are discarded. The response looks like this:

The extra data in the output above is spliced into the object instead of being under the  key.

Error messages in documentation
Error messages are documented in this wiki as shown below, which corresponds to the json error response in above:

The various error messages are:

Standard error messages
Some generic error messages are shared among modules. If a module can throw these errors, that's explicitly mentioned in its  section.

Additional notes

 * All error and warning outputs above use .  For , the field  will be replaced by.