sforkowany z mirror/soapbox
Mastodon: return a friendlier login error than 'invalid_grant'
rodzic
fcb378a5c9
commit
bb6cdd4b71
|
@ -163,10 +163,18 @@ export function logIn(intl, username, password) {
|
|||
return dispatch(createUserToken(username, password));
|
||||
}).catch(error => {
|
||||
if (error.response.data.error === 'mfa_required') {
|
||||
// If MFA is required, throw the error and handle it in the component.
|
||||
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));
|
||||
} else {
|
||||
// Return "wrong password" message.
|
||||
dispatch(snackbar.error(intl.formatMessage(messages.invalidCredentials)));
|
||||
}
|
||||
throw error;
|
||||
|
|
|
@ -23,7 +23,7 @@ export function obtainOAuthToken(params, baseURL) {
|
|||
dispatch({ type: OAUTH_TOKEN_CREATE_SUCCESS, params, token });
|
||||
return token;
|
||||
}).catch(error => {
|
||||
dispatch({ type: OAUTH_TOKEN_CREATE_FAIL, params, error });
|
||||
dispatch({ type: OAUTH_TOKEN_CREATE_FAIL, params, error, skipAlert: true });
|
||||
throw error;
|
||||
});
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue