github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/routes/allocations/allocation/task.js (about)

     1  /* eslint-disable ember/no-controller-access-in-routes */
     2  import { inject as service } from '@ember/service';
     3  import Route from '@ember/routing/route';
     4  import EmberError from '@ember/error';
     5  
     6  export default class TaskRoute extends Route {
     7    @service store;
     8  
     9    model({ name }) {
    10      const allocation = this.modelFor('allocations.allocation');
    11  
    12      // If there is no allocation, then there is no task.
    13      // Let the allocation route handle the 404 error.
    14      if (!allocation) return;
    15  
    16      const task = allocation.get('states').findBy('name', name);
    17  
    18      if (!task) {
    19        const err = new EmberError(
    20          `Task ${name} not found for allocation ${allocation.get('id')}`
    21        );
    22        err.code = '404';
    23        this.controllerFor('application').set('error', err);
    24      }
    25  
    26      return task;
    27    }
    28  }