mirror of https://github.com/status-im/consul.git
ui: Adds better error passthrough, disable/unauthorize properly on error (#5041)
1. Ensure any unexpected developer errors are passed through/shown 2. Previously when errors where returns/resolved the special isEnabled/isAuthorized would never get resolved. This was fine as they were set to false to start with anyway, but this resolves them again to false for completeness 3. Improved unit testing coverage
This commit is contained in:
parent
23a236ae95
commit
338527cc2e
|
@ -23,12 +23,15 @@ export default function(isValidServerError, P = Promise) {
|
||||||
}),
|
}),
|
||||||
[propName]: p
|
[propName]: p
|
||||||
.catch(function(e) {
|
.catch(function(e) {
|
||||||
|
if (e.errors && e.errors[0]) {
|
||||||
switch (e.errors[0].status) {
|
switch (e.errors[0].status) {
|
||||||
case '500':
|
case '500':
|
||||||
if (isValidServerError(e)) {
|
if (isValidServerError(e)) {
|
||||||
enable(true);
|
enable(true);
|
||||||
authorize(false);
|
authorize(false);
|
||||||
} else {
|
} else {
|
||||||
|
enable(false);
|
||||||
|
authorize(false);
|
||||||
return P.reject(e);
|
return P.reject(e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -46,6 +49,10 @@ export default function(isValidServerError, P = Promise) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
|
}
|
||||||
|
enable(false);
|
||||||
|
authorize(false);
|
||||||
|
throw e;
|
||||||
})
|
})
|
||||||
.then(function(res) {
|
.then(function(res) {
|
||||||
enable(true);
|
enable(true);
|
||||||
|
|
|
@ -1,10 +1,89 @@
|
||||||
|
import { module } from 'ember-qunit';
|
||||||
|
import test from 'ember-sinon-qunit/test-support/test';
|
||||||
import aclsStatus from 'consul-ui/utils/acls-status';
|
import aclsStatus from 'consul-ui/utils/acls-status';
|
||||||
import { module, test } from 'qunit';
|
|
||||||
|
|
||||||
module('Unit | Utility | acls status');
|
module('Unit | Utility | acls status');
|
||||||
|
|
||||||
// Replace this with your real tests.
|
test('it rejects and nothing is enabled or authorized', function(assert) {
|
||||||
test('it works', function(assert) {
|
const isValidServerError = this.stub().returns(false);
|
||||||
let result = aclsStatus();
|
const status = aclsStatus(isValidServerError);
|
||||||
assert.ok(result);
|
[
|
||||||
|
this.stub().rejects(),
|
||||||
|
this.stub().rejects({ errors: [] }),
|
||||||
|
this.stub().rejects({ errors: [{ status: '404' }] }),
|
||||||
|
].forEach(function(reject) {
|
||||||
|
const actual = status({
|
||||||
|
response: reject(),
|
||||||
|
});
|
||||||
|
assert.rejects(actual.response);
|
||||||
|
['isAuthorized', 'isEnabled'].forEach(function(prop) {
|
||||||
|
actual[prop].then(function(actual) {
|
||||||
|
assert.notOk(actual);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test('with a 401 it resolves with an empty array and nothing is enabled or authorized', function(assert) {
|
||||||
|
assert.expect(3);
|
||||||
|
const isValidServerError = this.stub().returns(false);
|
||||||
|
const status = aclsStatus(isValidServerError);
|
||||||
|
const actual = status({
|
||||||
|
response: this.stub().rejects({ errors: [{ status: '401' }] })(),
|
||||||
|
});
|
||||||
|
actual.response.then(function(actual) {
|
||||||
|
assert.deepEqual(actual, []);
|
||||||
|
});
|
||||||
|
['isAuthorized', 'isEnabled'].forEach(function(prop) {
|
||||||
|
actual[prop].then(function(actual) {
|
||||||
|
assert.notOk(actual);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test("with a 403 it resolves with an empty array and it's enabled but not authorized", function(assert) {
|
||||||
|
assert.expect(3);
|
||||||
|
const isValidServerError = this.stub().returns(false);
|
||||||
|
const status = aclsStatus(isValidServerError);
|
||||||
|
const actual = status({
|
||||||
|
response: this.stub().rejects({ errors: [{ status: '403' }] })(),
|
||||||
|
});
|
||||||
|
actual.response.then(function(actual) {
|
||||||
|
assert.deepEqual(actual, []);
|
||||||
|
});
|
||||||
|
actual.isEnabled.then(function(actual) {
|
||||||
|
assert.ok(actual);
|
||||||
|
});
|
||||||
|
actual.isAuthorized.then(function(actual) {
|
||||||
|
assert.notOk(actual);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test("with a 500 (but not a 'valid' error) it rejects and nothing is enabled or authorized", function(assert) {
|
||||||
|
assert.expect(3);
|
||||||
|
const isValidServerError = this.stub().returns(false);
|
||||||
|
const status = aclsStatus(isValidServerError);
|
||||||
|
const actual = status({
|
||||||
|
response: this.stub().rejects({ errors: [{ status: '500' }] })(),
|
||||||
|
});
|
||||||
|
assert.rejects(actual.response);
|
||||||
|
['isAuthorized', 'isEnabled'].forEach(function(prop) {
|
||||||
|
actual[prop].then(function(actual) {
|
||||||
|
assert.notOk(actual);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
test("with a 500 and a 'valid' error, it resolves with an empty array and it's enabled but not authorized", function(assert) {
|
||||||
|
assert.expect(3);
|
||||||
|
const isValidServerError = this.stub().returns(true);
|
||||||
|
const status = aclsStatus(isValidServerError);
|
||||||
|
const actual = status({
|
||||||
|
response: this.stub().rejects({ errors: [{ status: '500' }] })(),
|
||||||
|
});
|
||||||
|
actual.response.then(function(actual) {
|
||||||
|
assert.deepEqual(actual, []);
|
||||||
|
});
|
||||||
|
actual.isEnabled.then(function(actual) {
|
||||||
|
assert.ok(actual);
|
||||||
|
});
|
||||||
|
actual.isAuthorized.then(function(actual) {
|
||||||
|
assert.notOk(actual);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue