You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Improve signature of MatrixClient::isUsernameAvailable to not rely on throwing (#2130)
This commit is contained in:
committed by
GitHub
parent
033693283d
commit
a34426a7f6
@@ -6618,13 +6618,18 @@ export class MatrixClient extends EventEmitter {
|
||||
* Check whether a username is available prior to registration. An error response
|
||||
* indicates an invalid/unavailable username.
|
||||
* @param {string} username The username to check the availability of.
|
||||
* @return {Promise} Resolves: to `true`.
|
||||
* @return {Promise} Resolves: to boolean of whether the username is available.
|
||||
*/
|
||||
public isUsernameAvailable(username: string): Promise<true> {
|
||||
public isUsernameAvailable(username: string): Promise<boolean> {
|
||||
return this.http.authedRequest<{ available: true }>(
|
||||
undefined, Method.Get, '/register/available', { username: username },
|
||||
undefined, Method.Get, '/register/available', { username },
|
||||
).then((response) => {
|
||||
return response.available;
|
||||
}).catch(response => {
|
||||
if (response.errcode === "M_USER_IN_USE") {
|
||||
return false;
|
||||
}
|
||||
return Promise.reject(response);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user