aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGergő Tisza <tgr.huwiki@gmail.com>2025-02-17 15:55:57 +0100
committerGergő Tisza <tgr.huwiki@gmail.com>2025-02-17 17:04:31 +0100
commit8c78bad01be7658c879de851b4eede221ae2818b (patch)
treef809616ec492f32e4eb71fd674309610d3870987
parent440d1c0e2ee65fa234d3b3f9df8555d2b738c43d (diff)
downloadmediawikicore-8c78bad01be7658c879de851b4eede221ae2818b.tar.gz
mediawikicore-8c78bad01be7658c879de851b4eede221ae2818b.zip
auth: Log actual error message for action=login
Change-Id: I06acf62b6350f856905420263867ace754b6f79c
-rw-r--r--includes/api/ApiLogin.php17
1 files changed, 16 insertions, 1 deletions
diff --git a/includes/api/ApiLogin.php b/includes/api/ApiLogin.php
index e2e1bdac5570..f6f7aacbaa2f 100644
--- a/includes/api/ApiLogin.php
+++ b/includes/api/ApiLogin.php
@@ -88,6 +88,20 @@ class ApiLogin extends ApiBase {
}
/**
+ * Obtain an error code from a message, used for internal logs.
+ * @param Message|string|array $message
+ * @return string
+ */
+ private function getErrorCode( $message ) {
+ $message = Message::newFromSpecifier( $message );
+ if ( $message instanceof ApiMessage ) {
+ return $message->getApiCode();
+ } else {
+ return $message->getKey();
+ }
+ }
+
+ /**
* Executes the log-in attempt using the parameters passed. If
* the log-in succeeds, it attaches a cookie to the session
* and outputs the user id, username, and session token. If a
@@ -265,7 +279,8 @@ class ApiLogin extends ApiBase {
'successful' => $authRes === 'Success',
'accountType' => $this->identityUtils->getShortUserTypeInternal( $performer ),
'loginType' => $loginType,
- 'status' => $authRes,
+ 'status' => ( $authRes === 'Failed' && isset( $message ) ) ? $this->getErrorCode( $message ) : $authRes,
+ 'full_message' => isset( $message ) ? $this->formatMessage( $message ) : '',
] );
}