Mastodon: return a friendlier login error than 'invalid_grant'
This commit is contained in:
parent
fcb378a5c9
commit
bb6cdd4b71
2 changed files with 10 additions and 2 deletions
|
@ -163,10 +163,18 @@ export function logIn(intl, username, password) {
|
||||||
return dispatch(createUserToken(username, password));
|
return dispatch(createUserToken(username, password));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
if (error.response.data.error === 'mfa_required') {
|
if (error.response.data.error === 'mfa_required') {
|
||||||
|
// If MFA is required, throw the error and handle it in the component.
|
||||||
throw error;
|
throw error;
|
||||||
} else if(error.response.data.error) {
|
} else if (error.response.data.error === 'invalid_grant') {
|
||||||
|
// Mastodon returns this user-unfriendly error as a catch-all
|
||||||
|
// for everything from "bad request" to "wrong password".
|
||||||
|
// Assume our code is correct and it's a wrong password.
|
||||||
|
dispatch(snackbar.error(intl.formatMessage(messages.invalidCredentials)));
|
||||||
|
} else if (error.response.data.error) {
|
||||||
|
// If the backend returns an error, display it.
|
||||||
dispatch(snackbar.error(error.response.data.error));
|
dispatch(snackbar.error(error.response.data.error));
|
||||||
} else {
|
} else {
|
||||||
|
// Return "wrong password" message.
|
||||||
dispatch(snackbar.error(intl.formatMessage(messages.invalidCredentials)));
|
dispatch(snackbar.error(intl.formatMessage(messages.invalidCredentials)));
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -23,7 +23,7 @@ export function obtainOAuthToken(params, baseURL) {
|
||||||
dispatch({ type: OAUTH_TOKEN_CREATE_SUCCESS, params, token });
|
dispatch({ type: OAUTH_TOKEN_CREATE_SUCCESS, params, token });
|
||||||
return token;
|
return token;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: OAUTH_TOKEN_CREATE_FAIL, params, error });
|
dispatch({ type: OAUTH_TOKEN_CREATE_FAIL, params, error, skipAlert: true });
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue