BigW Consortium Gitlab

error.js 1.07 KB
Newer Older
1
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-console, quotes, prefer-template, max-len */
2 3
/* global u2f */

Fatih Acet committed
4 5
(function() {
  this.U2FError = (function() {
6
    function U2FError(errorCode, u2fFlowType) {
Fatih Acet committed
7
      this.errorCode = errorCode;
8
      this.message = this.message.bind(this);
Fatih Acet committed
9
      this.httpsDisabled = window.location.protocol !== 'https:';
10
      this.u2fFlowType = u2fFlowType;
Fatih Acet committed
11 12 13
    }

    U2FError.prototype.message = function() {
14 15 16 17 18
      if (this.errorCode === u2f.ErrorCodes.BAD_REQUEST && this.httpsDisabled) {
        return 'U2F only works with HTTPS-enabled websites. Contact your administrator for more details.';
      } else if (this.errorCode === 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.';
Fatih Acet committed
19
      }
20
      return "There was a problem communicating with your device.";
Fatih Acet committed
21 22 23 24
    };

    return U2FError;
  })();
25
}).call(window);