API:Errors and warnings/ja

From MediaWiki.org
Jump to navigation Jump to search
言語: English  • Deutsch • español • français • 日本語 • 한국어

API モジュールが何らかの原因で失敗した場合、エラーまたは警告が出力されます (although the HTTP response will usually still be 200 OK)。警告は、パラメーターが無効などの致命的ではない場合に、エラーは致命的な場合のみ使用されます。

警告[edit]

Warnings are output in the following format:

<?xml version="1.0" encoding="utf-8"?>
<api>
  <warnings>
    <query>Warning text
Another warning</query>
    <info>A warning from prop=info</info>
  </warnings>
</api>

As shown in the example, warnings are grouped by the name of the module that caused them. Multiple warnings from the same module are separated by a newline.

無効化されたモジュール[edit]

Disabled action=query submodules will always throw the following warning:

  • The "modulename" module has been disabled.

Missing module warnings[edit]

If you specify a module in a multi-value list, such as a list, meta, or prop list of query submodules, and the module is not present on a wiki, for example it is implemented by an extension that isn't loaded, then requesting throws the warning "Unrecognized value for parameter ..." and possibly additional warnings for the submodule's parameters. For example for a list query submodule, raremodule, a query such as

returns

  • "Unrecognized value for parameter 'list': raremodule"

See also Missing module errors below

You can check to see if a module is available before invoking it, see [How do I] check if an API module is available? in the FAQ.

パラメーター検証の警告[edit]

The MediaWiki API may return the following warnings 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

エラー[edit]

Error formats[edit]

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 (assuming format=json&formatversion=2):

{
    "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 will be missing if there is no extra data to display.)

The way the error message is returned to the client is controlled by the errorformat API parameter:

  • 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.
        "text": "<like wikitext, but with added plaintext conversion>",
    
    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.
  • raw: intended as a machine-readable format (note that the error key is more unique than the error code).
        "key": "<message key>",
        "params": [...message parameters...],
    
    Parameters can themselves be objects with key and params fields.
  • none: no message information at all.

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[edit]

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...
    }
}

(ie. extra data is spliced into the object instead of being under the data key).

With format=xml it looks like this:

<error code="error-code" info="...." />

ドキュメントのエラーメッセージ[edit]

エラーメッセージは次のように文章にされます:

コード 情報
apparams prlevel は prtype なしでは使用できません

対応するものは次の通りです(訳注: 分かりやすくするために日本語訳):

<error code="apparams" info="prlevelはprtype無しで使うことができません" />

for XML or:

"error": {
    "code": "maxlagapparams",
    "info": "prlevel may not be used without prtype",
    "*": "See https://www.mediawiki.org/w/api.php for API usage."
}

for json. When using a different formatversion than 1 with json, the "*" field will be named "docref" instead.

無効化されたモジュール[edit]

Disabled action= modules will always fail with the following error:

コード 情報
moduledisabled The modulename module has been disabled.

Missing module errors[edit]

If you specify a module as the single value of a parameter such as action and it is not present on a wiki, for example it is implemented by an extension that isn't loaded, then the request throws the error

Code Info
unknown_action Unrecognized value for parameter 'action': modulename

You can check to see if a module is available before invoking it, see [How do I] check if an API module is available? in the FAQ.

See also Missing module warnings above.

パラメーター検証のエラー[edit]

The MediaWiki API can "throw" the following errors when validating parameters of any API modules.

コード 情報
multival_paramname Only one of 'value1', 'value2', 'value3' is allowed for parameter 'paramname'
unknown_paramname Unrecognized value for parameter paramname: value.
paramname paramname may not be less than min (set to value).
paramname paramname may not be over max (set to value) for bots or sysops.
paramname paramname may not be over max (set to value) for users.
badtimestamp_paramname Invalid value "value" for timestamp parameter paramname.
baduser_paramname Invalid value "value" for user parameter 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

標準的なエラーメッセージ[edit]

一般的なエラー メッセージの中にはモジュール間で共有されるものがあります。モジュールがこれらのエラーをスローする場合、Possible errorsセクションで明示的に言及されます。

コード 情報
unknownerror 不明なエラー: This usually means something crazy like a rare race condition occurred. If you get this error, retry your request until it succeeds or returns a more informative error message
unknownerror 不明なエラー errorcode
unknownerror-nocode Unknown error
unsupportednamespace Special 名前空間内のページは編集できません
protectednamespace-interface あなたはインターフェイス メッセージを編集することを許可されていません
protectednamespace namespace」名前空間内のページの編集することを許可されていません
customcssjsprotected あなたは CSS ページや JavaScript ページを編集することを許可されていません
cascadeprotected あなたが編集しようとしているページは、カスケード保護されたページで参照読み込みされているため、保護されています。
protectedpage このページを編集するには「right」の権限が必要です
permissiondenied パーミッションが拒否されました
confirmemail You must confirm your e-mail address before you can edit
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 現在、ウィキは読み取り専用モードになっています
badtoken 無効なトークンです (urlencode するのを忘れていませんか?)
missingtitle リクエストしたページは存在しません
mustbeposted Type of your HTTP request message must be POST
hookaborted The modification you tried to make was aborted by an extension hook
nosuchpageid ID id のページはありません
nosuchrevid ID id の版はありません
nosuchrcid There is no change with rcid "id"
nosuchuser 指定した利用者は存在しません
invalidtitle 無効なページ名「title
invaliduser 無効な利用者名「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