github.com/hernad/nomad@v1.6.112/ui/app/routes/allocations/allocation/task.js (about)

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