github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/controllers/application.js (about)

     1  /* eslint-disable ember/no-observers */
     2  import { inject as service } from '@ember/service';
     3  import Controller from '@ember/controller';
     4  import { run } from '@ember/runloop';
     5  import { observes } from '@ember-decorators/object';
     6  import { computed } from '@ember/object';
     7  import Ember from 'ember';
     8  import codesForError from '../utils/codes-for-error';
     9  import NoLeaderError from '../utils/no-leader-error';
    10  import classic from 'ember-classic-decorator';
    11  
    12  @classic
    13  export default class ApplicationController extends Controller {
    14    @service config;
    15    @service system;
    16  
    17    queryParams = [
    18      {
    19        region: 'region',
    20      },
    21    ];
    22  
    23    region = null;
    24  
    25    error = null;
    26  
    27    @computed('error')
    28    get errorStr() {
    29      return this.error.toString();
    30    }
    31  
    32    @computed('error')
    33    get errorCodes() {
    34      return codesForError(this.error);
    35    }
    36  
    37    @computed('errorCodes.[]')
    38    get is403() {
    39      return this.errorCodes.includes('403');
    40    }
    41  
    42    @computed('errorCodes.[]')
    43    get is404() {
    44      return this.errorCodes.includes('404');
    45    }
    46  
    47    @computed('errorCodes.[]')
    48    get is500() {
    49      return this.errorCodes.includes('500');
    50    }
    51  
    52    @computed('error')
    53    get isNoLeader() {
    54      const error = this.error;
    55      return error instanceof NoLeaderError;
    56    }
    57  
    58    @observes('error')
    59    throwError() {
    60      if (this.get('config.isDev')) {
    61        run.next(() => {
    62          throw this.error;
    63        });
    64      } else if (!Ember.testing) {
    65        run.next(() => {
    66          // eslint-disable-next-line
    67          console.warn('UNRECOVERABLE ERROR:', this.error);
    68        });
    69      }
    70    }
    71  }