mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 01:45:44 +03:00
Handle 403s gracefully
- When a list 403s, treat it as if it were empty - When a single resource 403s, redirect to an application error page that has a backdoor link to the tokens page
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import Ember from 'ember';
|
||||
import RESTAdapter from 'ember-data/adapters/rest';
|
||||
import codesForError from '../utils/codes-for-error';
|
||||
|
||||
const { get, computed, inject } = Ember;
|
||||
|
||||
@@ -21,8 +22,12 @@ export default RESTAdapter.extend({
|
||||
|
||||
findAll() {
|
||||
return this._super(...arguments).catch(error => {
|
||||
if (error.code === '501' || (error.errors && error.errors.findBy('status', '501'))) {
|
||||
// Feature is not implemented in this version of Nomad
|
||||
const errorCodes = codesForError(error);
|
||||
|
||||
const isNotAuthorized = errorCodes.includes('403');
|
||||
const isNotImplemented = errorCodes.includes('501');
|
||||
|
||||
if (isNotAuthorized || isNotImplemented) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Ember from 'ember';
|
||||
import codesForError from '../utils/codes-for-error';
|
||||
|
||||
const { Controller, computed, inject, run, observer } = Ember;
|
||||
|
||||
@@ -12,19 +13,7 @@ export default Controller.extend({
|
||||
}),
|
||||
|
||||
errorCodes: computed('error', function() {
|
||||
const error = this.get('error');
|
||||
const codes = [error.code];
|
||||
|
||||
if (error.errors) {
|
||||
error.errors.forEach(err => {
|
||||
codes.push(err.status);
|
||||
});
|
||||
}
|
||||
|
||||
return codes
|
||||
.compact()
|
||||
.uniq()
|
||||
.map(code => '' + code);
|
||||
return codesForError(this.get('error'));
|
||||
}),
|
||||
|
||||
is403: computed('errorCodes.[]', function() {
|
||||
|
||||
15
ui/app/utils/codes-for-error.js
Normal file
15
ui/app/utils/codes-for-error.js
Normal file
@@ -0,0 +1,15 @@
|
||||
// Returns an array of error codes as strings for an Ember error object
|
||||
export default function codesForError(error) {
|
||||
const codes = [error.code];
|
||||
|
||||
if (error.errors) {
|
||||
error.errors.forEach(err => {
|
||||
codes.push(err.status);
|
||||
});
|
||||
}
|
||||
|
||||
return codes
|
||||
.compact()
|
||||
.uniq()
|
||||
.map(code => '' + code);
|
||||
}
|
||||
Reference in New Issue
Block a user