2019-04-30 15:12:25 -04:00
|
|
|
import { __ } from '~/locale';
|
|
|
|
|
2017-10-09 18:21:56 -04:00
|
|
|
export default class U2FError {
|
|
|
|
constructor(errorCode, u2fFlowType) {
|
|
|
|
this.errorCode = errorCode;
|
|
|
|
this.message = this.message.bind(this);
|
|
|
|
this.httpsDisabled = window.location.protocol !== 'https:';
|
|
|
|
this.u2fFlowType = u2fFlowType;
|
|
|
|
}
|
2016-12-14 00:26:26 -05:00
|
|
|
|
2017-10-09 18:21:56 -04:00
|
|
|
message() {
|
|
|
|
if (this.errorCode === window.u2f.ErrorCodes.BAD_REQUEST && this.httpsDisabled) {
|
2019-04-30 15:12:25 -04:00
|
|
|
return __(
|
|
|
|
'U2F only works with HTTPS-enabled websites. Contact your administrator for more details.',
|
|
|
|
);
|
2017-10-09 18:21:56 -04:00
|
|
|
} else if (this.errorCode === window.u2f.ErrorCodes.DEVICE_INELIGIBLE) {
|
|
|
|
if (this.u2fFlowType === 'authenticate') {
|
2019-04-30 15:12:25 -04:00
|
|
|
return __('This device has not been registered with us.');
|
2016-07-24 16:45:11 -04:00
|
|
|
}
|
2017-10-09 18:21:56 -04:00
|
|
|
if (this.u2fFlowType === 'register') {
|
2019-04-30 15:12:25 -04:00
|
|
|
return __('This device has already been registered with us.');
|
2017-10-09 18:21:56 -04:00
|
|
|
}
|
|
|
|
}
|
2019-04-30 15:12:25 -04:00
|
|
|
return __('There was a problem communicating with your device.');
|
2017-10-09 18:21:56 -04:00
|
|
|
}
|
|
|
|
}
|