diff --git a/ui/core/app/routes/orgs/org/projects.js b/ui/core/app/routes/orgs/org/projects.js index 11beb0531..ee50e8f8a 100644 --- a/ui/core/app/routes/orgs/org/projects.js +++ b/ui/core/app/routes/orgs/org/projects.js @@ -7,11 +7,7 @@ export default class OrgsOrgProjectsRoute extends Route { * Returns all projects from the store. * @return {Promise[ProjectModel]} */ - async model() { - try { - return await this.store.findAll('project'); - } catch (e) { - return []; - } + model() { + return this.store.findAll('project'); } } diff --git a/ui/core/app/templates/orgs/org/error.hbs b/ui/core/app/templates/orgs/org/error.hbs new file mode 100644 index 000000000..be87afd4d --- /dev/null +++ b/ui/core/app/templates/orgs/org/error.hbs @@ -0,0 +1,39 @@ +{{!-- + In an error route, the error instance is `@model`. Error instances contain + a list of errors, each of which has one convenience boolean set on it: + + * Error booleans are attached based on the error status code: + * + * - `error.isUnauthenticated`: the session isn't authenticated + * - `error.isForbidden`: the session is authenticated but does not have + * permission to perform the requested action + * - `error.isNotFound`: the requested resource could not be found + * - `error.isServer`: an internal server error occurred + * - `error.isUnknown`: an error occurred, but we don't know which or + * we don't distinguish it yet + +--}} + +{{#each @model.errors as |error|}} + + {{#if error.isUnauthenticated}} + {{!-- error.status === 401 --}} + {{/if}} + + {{#if error.isForbidden}} + {{!-- error.status === 403 --}} + {{/if}} + + {{#if error.isNotFound}} + {{!-- error.status === 404 --}} + {{/if}} + + {{#if error.isServer}} + {{!-- error.status === 500 --}} + {{/if}} + + {{#if error.isUnknown}} + {{!-- error.status === 🤷 --}} + {{/if}} + +{{/each}} diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index 7ff10e439..c98942919 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -28,4 +28,8 @@ export default function() { this.get('/orgs/:org_id/projects/:project_id/host-catalogs/:id'); this.patch('/orgs/:org_id/projects/:project_id/host-catalogs/:id'); this.del('/orgs/:org_id/projects/:project_id/host-catalogs/:id'); + + // Uncomment the following line and the Response import above + // Then change the response code to simulate error responses + //this.get('/orgs/:org_id/projects', () => new Response(401)); } diff --git a/ui/core/mirage/serializers/application.js b/ui/core/mirage/serializers/application.js index bed25389e..1c3821b4b 100644 --- a/ui/core/mirage/serializers/application.js +++ b/ui/core/mirage/serializers/application.js @@ -1,5 +1,6 @@ import { RestSerializer } from 'ember-cli-mirage'; import { underscore } from '@ember/string'; +import { isArray } from '@ember/array'; /** * Manages serialization/normalization of data into and out of the mock API. @@ -38,7 +39,7 @@ export default RestSerializer.extend({ serialize() { let json = RestSerializer.prototype.serialize.apply(this, arguments); // If array, root it under a standard `items` key - if (json.length) json = {items: json}; + if (isArray(json)) json = {items: json}; return json; },