Files
threshold-ui/ui/admin/app/components/error/message.js
T

60 lines
1.7 KiB
JavaScript
Raw Normal View History

import MessageComponent from 'rose/components/rose/message';
2020-09-18 12:00:52 -04:00
import { computed } from '@ember/object';
2020-09-14 10:31:43 -04:00
/*
* Helpful error booleans are attached based on the error status code:
*
* - 401 - `error.isUnauthenticated`: the session isn't authenticated
* - 403 - `error.isForbidden`: the session is authenticated but does not have
* permission to perform the requested action
* - 404 - `error.isNotFound`: the requested resource could not be found
* - 500 - `error.isServer`: an internal server error occurred
*
* For an unknown error state, i.e error state not matching to the above defined list:
* - unknown - `error.isUnknown`: an error occurred, but we don't know which or
* we don't distinguish it yet
*/
2020-09-14 10:31:43 -04:00
2020-09-18 12:00:52 -04:00
const statuses = ['401', '403', '404', '500'];
2020-09-14 10:31:43 -04:00
export default class ErrorMessageComponent extends MessageComponent {
2020-09-14 10:31:43 -04:00
// =methods
/**
2020-09-18 12:00:52 -04:00
* Returns an icon for error status.
2020-09-14 10:31:43 -04:00
* @return {string}
*/
@computed('args.status')
2020-09-14 10:31:43 -04:00
get icon() {
switch (this.args.status) {
2020-09-18 12:00:52 -04:00
case '401':
case '403':
return 'disabled';
case '404':
return 'help-circle-outline';
default:
return 'alert-circle-outline';
}
2020-09-14 10:31:43 -04:00
}
2020-09-18 12:00:52 -04:00
// TODO: Enable when help documentation can be linked in.
2020-09-14 10:31:43 -04:00
/**
* Returns an route string for help text in message.
* @return {string}
*/
// get helpRoute() {
// return 'index'
// }
2020-09-14 10:31:43 -04:00
/**
2020-09-18 12:00:52 -04:00
* Returns 'unknown' status code when provided error status
* isn't part of predefined statuses.
* @return {string}
2020-09-14 10:31:43 -04:00
*/
@computed('args.status')
2020-09-18 14:22:54 -04:00
get messageCode() {
let messageCode = this.args.status;
2020-11-16 15:08:59 -05:00
if (!statuses.includes(messageCode)) messageCode = 'unknown';
2020-09-18 14:22:54 -04:00
return messageCode;
2020-09-14 10:31:43 -04:00
}
}