API:Errors and warnings/ja

Category:MediaWiki action API/ja

API リクエストで何か間違っている場合、(たいてい HTTP レスポンスは 200 OK のままですが)警告またはエラーがスローされます。 警告は無効なパラメーターのような致命的でない状況でのみスローされるのに対して、エラーは致命的な状況でのみスローされます。

警告

警告は原因となるモジュールの名前によってグループ化されます。 同一モジュールからの複数の警告は改行によって分離されます。 既定であるレガシーエラー形式モード(下記参照)では、警告は以下の形式で出力されます:

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

formatversion=2 が使用されると、 *warnings に置き換えられます。)

レガシーエラー形式でないオプションを使用すると、警告はエラーと同じ形式で出力されます。 例えば、 errorformat=wikitext 形式では:

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

formatversion=2 が使用されると、 *text に置き換えられます。)

警告メッセージ

種類説明警告メッセージ
Disabled submoduleThe 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 submoduleThe 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 validationWarnings 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

エラー

エラー形式

MediaWiki 1.29 以降、エラーは地域化可能であり、複数の形式で利用可能です。 エラー(または警告)はメッセージ、エラーコード(任意の文字列、通常メッセージキーから生成される。後述の#標準エラーメッセージも参照)、およびオプションの追加データ(連想配列)で構成されることが期待されます。 エラーがあるAPIレスポンスはこのようになります:

{
    "errors": [
        {
            "code": "エラーコード",
            /* ...エラーメッセージ..., */
            "data": [ /* ...任意の追加データ... */ ],
            "module": "エラーが生成されたAPIモジュールへのパス"
        },
        /* ...さらなるエラー... */
    ],
    "docref": "ヘルプがどこで見つかるかについて人間可読なメッセージ"
}

表示すべき追加データがない場合は、上記の出力の data キーはありません。

クライアントに返される上記のエラーメッセージ出力方法は、 errorformat API パラメーターによって制御されます。 様々なエラー形式が利用可能です:

形式説明出力
htmlIntended for human display in HTML-capable clients. MediaWiki will ensure that the HTML is safe; it is just as trustworthy as article content (both are parsed Wikitext).
    "html": "the message, interpreted as wikitext and parsed into HTML"
wikitext
    "text": "the message as-is, with parameter substitution but without any parsing"
plaintextIntended 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"
rawIntended 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... */ ]
noneNo message information at all.
bcThe default, for backward compatibility. There’s no point in specifying this value, use one of the non-legacy formats instead.#レガシー形式参照

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

API responses can contain multiple errors. For an example, try adding the lines the abusefilter will block this and the abusefilter will also block this to a Test Wikipedia page as API sandbox (if you are logged in, go to the action=edit tab and click トークンを自動入力します first before making the request).

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

レガシー形式

レガシーエラー形式では、常にエラーは多くともひとつで、追加のエラーは破棄されます。 レスポンスはこのようになります:

{
    "error": {
        "code": "エラーコード",
        "info": "そのままのメッセージ、パラメーターは置換されるが構文解析はされない",
        /* ...任意の追加データ... */
    }
}

上記の出力で追加データは data キーの下にあるのではなく、オブジェクトに継ぎ足されています。


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:

コード情報
エラーコードエラーメッセージ

様々なエラーメッセージ:

種類説明エラーメッセージ
コード情報
Disabled moduleThe 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.moduledisabledThe modulename module has been disabled.
Missing moduleThe action module is not present in the wiki, for example if it is implemented by an extension that isn't loadedunknown_actionUnrecognized value for parameter action: modulename.
Parameter validationErrors thrown when validating parameters of any API module. paramname is replaced by the name of the parameter.multival_paramnameOnly one of 'value1', 'value2', 'value3' is allowed for parameter 'paramname'
unknown_paramnameUnrecognized value for parameter paramname: value.
paramnameparamname may not be less than min (set to value).
paramnameparamname may not be over max (set to value) for bots or sysops.
paramnameparamname may not be over max (set to value) for users.
badtimestamp_paramnameInvalid value "value" for timestamp parameter paramname.
baduser_paramnameInvalid value "value" for user parameter paramname.
invalidparammixThe parameters param1, param2, param3 cannot be used together
missingparamOne of the parameters param1, param2, param3 is required
_badcontinueInvalid continue param. You should pass the original value returned by the previous query

標準エラーメッセージ

いくつかの包括的なエラーメッセージがモジュール間で共有されています。 If a module can throw these errors, that's explicitly mentioned in its Possible errors section.

コード情報
unknownerrorUnknown error: 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不明なエラーです。
unsupportednamespacePages in the Special namespace can't be edited
protectednamespace-interfaceYou're not allowed to edit interface messages
protectednamespaceYou're not allowed to edit pages in the "namespace" namespace
customcssjsprotectedYou're not allowed to edit custom CSS and JavaScript pages
cascadeprotectedこのページは、「カスケード保護」が指定された状態で保護されている以下のページで参照読み込みされているため、編集できないように保護されています:

list of cascade-protected pages

protectedpageThe "right" right is required to edit this page
permissiondeniedアクセスが拒否されました。
confirmemailページの編集を始める前にメールアドレスの確認をする必要があります。

個人設定でメールアドレスを設定し、確認を行ってください。

blockedYou have been blocked from editing
autoblockedYour IP address has been blocked automatically, because it was used by a blocked user
ratelimitedYou've exceeded your rate limit. Please wait some time and try again
readonlyThe wiki is currently in read-only mode
badtokenInvalid token (did you remember to urlencode it?)
missingtitleThe page you requested doesn't exist
mustbepostedType of your HTTP request message must be POST
hookabortedThe modification you tried to make was aborted by an extension hook
nosuchpageidThere is no page with ID id
nosuchrevidThere is no revision with ID id
nosuchrcidThere is no change with rcid "id"
nosuchuserThe user you specified doesn't exist
invalidtitleBad title "title"
invaliduserInvalid 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
readapideniedYou need read permission to use this module
noapiwriteEditing of this wiki through the API is disabled. Make sure the $wgEnableWriteAPI=true; statement is included in the wiki's LocalSettings.php file

追記

  • 上記のエラーおよび警告の出力はすべて format=json&formatversion=2 を使用しています。 formatversion=1 では、フィールド docref* で置き換えられます。
Category:MediaWiki action API/ja