summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/authentication/u2f/error.js
blob: ca0fc0700ad00f324d509e25bd1a4edf7bbbf4f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { __ } from '~/locale';

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;
  }

  message() {
    if (this.errorCode === window.u2f.ErrorCodes.BAD_REQUEST && this.httpsDisabled) {
      return __(
        'U2F only works with HTTPS-enabled websites. Contact your administrator for more details.',
      );
    } else if (this.errorCode === window.u2f.ErrorCodes.DEVICE_INELIGIBLE) {
      if (this.u2fFlowType === 'authenticate') {
        return __('This device has not been registered with us.');
      }
      if (this.u2fFlowType === 'register') {
        return __('This device has already been registered with us.');
      }
    }
    return __('There was a problem communicating with your device.');
  }
}