github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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 { next } 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 OTTExchangeError from '../utils/ott-exchange-error'; 11 import classic from 'ember-classic-decorator'; 12 // eslint-disable-next-line no-unused-vars 13 import KeyboardService from '../services/keyboard'; 14 @classic 15 export default class ApplicationController extends Controller { 16 @service config; 17 @service system; 18 @service token; 19 @service flashMessages; 20 21 /** 22 * @type {KeyboardService} 23 */ 24 @service keyboard; 25 26 // eslint-disable-next-line ember/classic-decorator-hooks 27 constructor() { 28 super(...arguments); 29 this.keyboard.listenForKeypress(); 30 } 31 32 queryParams = [ 33 { 34 region: 'region', 35 }, 36 { 37 oneTimeToken: 'ott', 38 }, 39 ]; 40 41 region = null; 42 43 oneTimeToken = ''; 44 45 error = null; 46 47 @computed('error') 48 get errorStr() { 49 return this.error.toString(); 50 } 51 52 @computed('error') 53 get errorCodes() { 54 return codesForError(this.error); 55 } 56 57 @computed('errorCodes.[]') 58 get is403() { 59 return this.errorCodes.includes('403'); 60 } 61 62 @computed('errorCodes.[]') 63 get is404() { 64 return this.errorCodes.includes('404'); 65 } 66 67 @computed('errorCodes.[]') 68 get is500() { 69 return this.errorCodes.includes('500'); 70 } 71 72 @computed('error') 73 get isNoLeader() { 74 const error = this.error; 75 return error instanceof NoLeaderError; 76 } 77 78 @computed('error') 79 get isOTTExchange() { 80 const error = this.error; 81 return error instanceof OTTExchangeError; 82 } 83 84 @observes('error') 85 throwError() { 86 if (this.get('config.isDev')) { 87 next(() => { 88 throw this.error; 89 }); 90 } else if (!Ember.testing) { 91 next(() => { 92 // eslint-disable-next-line 93 console.warn('UNRECOVERABLE ERROR:', this.error); 94 }); 95 } 96 } 97 }