API:Errores y advertencias

From mediawiki.org
This page is a translated version of the page API:Errors and warnings and the translation is 24% complete.

Si algo sale mal en uan solicitud a la API, un error o advertencia aparecerá (aunque la respuesta HTTP usualmente seguirá siendo 200 OK). Las advertencias aparecen con condiciones no fatales, como parámetros no válidos, mientras que los errores solo aparecen con condiciones fatales.

Advertencia

Las advertencias se agrupan por el nombre del módulo que las causa. Múltiples advertencias del mismo módulo están separadas por una nueva línea. En el modo de formato de error heredado (ver a continuación), que es el predeterminado, las advertencias se emiten en el siguiente formato:

"warnings": {
    "modulename": {
      "*": "warning text"
    }
  }

(* será reemplazado por warnings cuando se use formatversion=2.)

Cuando se utiliza una opción de formato de error no heredada, las advertencias se generan en el mismo formato que los errores. Por ejemplo con errorformat=wikitext el formato será:

"warnings": [
    {
        "code": "warning message key",
        "*": "text of warning",
        "module": "API module which caused the warning"
    }
]

(* will be replaced with text when formatversion=2 is used.)

Mensajes de advertencia

Tipo Descripción Mensaje(s) de advertencia
Disabled submodule The action=query submodule has been disabled in the wiki. To check if a module is available before invoking it, see How do I check if an API module is available? in the FAQ. The submodulename module has been disabled.
Missing submodule The list, prop or meta submodule is not present in the wiki, for example if it is implemented by an extension that isn't loaded. Unrecognized value for parameter list=submodule.
Parameter validation Warnings thrown when validating parameters of any API module. paramname is replaced by the name of the parameter.
  • Too many values supplied for parameter paramname: the limit is limit.
  • Unrecognized value for parameter paramname: value.
  • Unrecognized values for parameter paramname: value1, value2, value3

Errors

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 #Standard error messages below), and optional extra data (an associative array). An API response with errors will look like this:

{
    "errors": [
        {
            "code": "error-code",
            /* ...error message..., */
            "data": [ /* ...any extra data... */ ],
            "module": "path to the API module that generated the error"
        },
        /* ...more errors... */
    ],
    "docref": "human-readable message on where to find help"
}

The data 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 errorformat API parameter. The various error formats available are:

Format Description Output
html Intended for human display in HTML-capable clients
    "html": "the message, interpreted as wikitext and parsed into HTML"
wikitext
    "text": "the message as-is, with parameter substitution but without any parsing"
plaintext Intended for human display in HTML-incapable clients. Plaintext conversion is a minimal, best-effort transformation to make the message (assumed to contain wikitext) more readable: tags are removed, HTML entities are replaced, certain HTML tags are intelligently replaced with punctuation.
    "text": "the message, like wikitext, but with added plaintext conversion"
raw Intended as a machine-readable format (note that the error key is more unique than the error code). Parameters can themselves be objects with key and params fields.
    "key": "message key",
    "params": [ /* ...message parameters... */ ]
none No message information at all.
bc The default, for backward compatibility. There’s no point in specifying this value, use one of the non-legacy formats instead. See #Legacy format

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

Error codes are also returned in the MediaWiki-API-Error 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 errorformat is not set (or set to bc), 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:

{
    "error": {
        "code": "error-code",
        "info": "the message as-is, with parameter substitution but without any parsing",
        /* ...any extra data... */
    }
}

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

Error messages in documentation

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

Code Info
errorcode error message

The various error messages are:

Type Description Error message(s)
Code Info
Disabled module The action module has been disabled in the wiki. To check if a module is available before invoking it, see How do I check if an API module is available? in the FAQ. moduledisabled The modulename module has been disabled.
Missing module The action module is not present in the wiki, for example if it is implemented by an extension that isn't loaded unknown_action Unrecognized value for parameter action: modulename.
Parameter validation Errors thrown when validating parameters of any API module. paramname is replaced by the name of the parameter. multival_paramname Only one of 'value1', 'value2', 'value3' is allowed for parameter 'paramname'
unknown_paramname Valor no reconocido para el parámetro paramname: value.
paramname paramname no puede ser menor que min (fijado a value).
paramname paramname no puede ser mayor que max (fijado a value) para bots o administradores de sistema.
paramname paramname no puede ser mayor que max (fijado a value) para usuarios.
badtimestamp_paramname El valor «value» no es válido para el parámetro de cronomarcación paramname.
baduser_paramname Valor no válido "value" para el parámetro de usuario paramname.
invalidparammix The parameters param1, param2, param3 cannot be used together
missingparam One of the parameters param1, param2, param3 is required
_badcontinue Invalid continue param. You should pass the original value returned by the previous query

Mensajes de error estándar

Algunos mensajes de errores genéricos son compartidos entre módulos. Si un módulo puede emitir estos errores, se menciona explícitamente en su sección de Posibles errores.

Código Info
unknownerror Unknown error: This usually means something crazy like a rare race condition occurred. Si te topas con este error, vuelve a hacer tu solicitud hasta que salga bien o devuelva un mensaje de error con más información.
unknownerror Error desconocido: «errorcode»
unknownerror-nocode Error desconocido.
unsupportednamespace Pages in the Special namespace can't be edited
protectednamespace-interface You're not allowed to edit interface messages
protectednamespace You're not allowed to edit pages in the "namespace" namespace
customcssjsprotected You're not allowed to edit custom CSS and JavaScript pages
cascadeprotected Esta página ha sido protegida contra edición porque está transcluida en las siguientes páginas protegidas con la opción de «cascada» activa:

lista de páginas protegidas en cascada

protectedpage The "right" right is required to edit this page
permissiondenied Permiso denegado.
confirmemail Debes confirmar tu dirección de correo electrónico antes de poder editar páginas. Por favor, configura y confirma tu dirección de correo a través de tus preferencias de usuario.
blocked You have been blocked from editing
autoblocked Your IP address has been blocked automatically, because it was used by a blocked user
ratelimited You've exceeded your rate limit. Please wait some time and try again
readonly The wiki is currently in read-only mode
badtoken Invalid token (did you remember to urlencode it?)
missingtitle The page you requested doesn't exist
mustbeposted Type of your HTTP request message must be POST
hookaborted The modification you tried to make was aborted by an extension hook
nosuchpageid There is no page with ID id
nosuchrevid There is no revision with ID id
nosuchrcid There is no change with rcid "id"
nosuchuser The user you specified doesn't exist
invalidtitle Bad title "title"
invaliduser Invalid username "username"
assertbotfailed "assert=bot" has been used, but logged in user is not a bot
assertuserfailed "assert=user" has been used, but user is not logged in
readapidenied You need read permission to use this module
noapiwrite Editing of this wiki through the API is disabled. Make sure the $wgEnableWriteAPI=true; statement is included in the wiki's LocalSettings.php file

Notas adicionales

  • Todas las salidas de errores y advertencias anteriores usan format=json&formatversion=2. Para formatversion=1, el campo docref será reemplazado por *.