#313: improve logging in auth states

This commit is contained in:
SleepWalker 2017-03-02 07:58:33 +02:00
parent 09baa2a398
commit e9e04d8336
10 changed files with 30 additions and 9 deletions

View File

@ -17,7 +17,9 @@ export default class AcceptRulesState extends AbstractState {
resolve(context) {
context.run('acceptRules')
.then(() => context.setState(new CompleteState()))
.catch((err = {}) => err.errors || logger.warn(err));
.catch((err = {}) =>
err.errors || logger.warn('Error accepting rules', err)
);
}
reject(context) {

View File

@ -21,7 +21,9 @@ export default class ActivationState extends AbstractState {
resolve(context, payload) {
context.run('activate', payload)
.then(() => context.setState(new CompleteState()))
.catch((err = {}) => err.errors || logger.warn(err));
.catch((err = {}) =>
err.errors || logger.warn('Error activating account', err)
);
}
reject(context) {

View File

@ -85,7 +85,7 @@ export default class AuthFlow {
if (this.onReady) {
const callback = this.onReady;
this.onReady = () => {};
return resp.then(callback, (err) => err || logger.warn(err));
return resp.then(callback, (err) => err || logger.warn('State transition error', err));
}
return resp;

View File

@ -24,7 +24,9 @@ export default class LoginState extends AbstractState {
resolve(context, payload) {
context.run('login', payload)
.then(() => context.setState(new PasswordState()))
.catch((err = {}) => err.errors || logger.warn(err));
.catch((err = {}) =>
err.errors || logger.warn('Error validating login', err)
);
}
goBack(context) {

View File

@ -25,7 +25,9 @@ export default class PasswordState extends AbstractState {
login
})
.then(() => context.setState(new CompleteState()))
.catch((err = {}) => err.errors || logger.warn(err));
.catch((err = {}) =>
err.errors || logger.warn('Error logging in', err)
);
}
reject(context) {

View File

@ -21,7 +21,9 @@ export default class RecoverPasswordState extends AbstractState {
resolve(context, payload) {
context.run('recoverPassword', payload)
.then(() => context.setState(new CompleteState()))
.catch((err = {}) => err.errors || logger.warn(err));
.catch((err = {}) =>
err.errors || logger.warn('Error recovering password', err)
);
}
goBack(context) {

View File

@ -13,7 +13,9 @@ export default class RegisterState extends AbstractState {
resolve(context, payload) {
context.run('register', payload)
.then(() => context.setState(new CompleteState()))
.catch((err = {}) => err.errors || logger.warn(err));
.catch((err = {}) =>
err.errors || logger.warn('Error registering', err)
);
}
reject(context, payload) {

View File

@ -19,7 +19,9 @@ export default class ResendActivationState extends AbstractState {
resolve(context, payload) {
context.run('resendActivation', payload)
.then(() => context.setState(new ActivationState()))
.catch((err = {}) => err.errors || logger.warn(err));
.catch((err = {}) =>
err.errors || logger.warn('Error resending activation', err)
);
}
reject(context) {

View File

@ -65,6 +65,13 @@ const logger = {
return;
}
if (typeof context !== 'object') {
// it would better to always have an object here
context = {
message: context
};
}
console[method](message, context); // eslint-disable-line
Raven.captureException(message, {

View File

@ -14,7 +14,7 @@ describe('<ChangePassword />', () => {
it('should call onSubmit if passwords entered', () => {
const onSubmit = sinon.spy().named('onSubmit');
const onSubmit = sinon.spy(() => ({catch: () => {}})).named('onSubmit');
const component = shallow(<ChangePassword onSubmit={onSubmit} />);
component.find('Form').simulate('submit');