Fix bug with umwarranted error messages

This commit is contained in:
Nathan Barber
2021-12-13 20:36:00 -05:00
parent 3893fb6d2c
commit 4704217dc5
4 changed files with 34 additions and 30 deletions

View File

@@ -110,13 +110,21 @@ const GroupEdit = (props) => {
Promise.all(promiseQueue) Promise.all(promiseQueue)
.then((data) => { .then((data) => {
data.status < 300 // ensure status of all requests are < 300
let allPassed =
data.map((e) => e.status).filter((e) => e >= 300).length ==
0;
allPassed
? updateGroups(0, limit) ? updateGroups(0, limit)
.then((data) => dispatchPageUpdate(data, 0)) .then((data) => dispatchPageUpdate(data, 0))
.then(() => history.push("/groups")) .then(() => history.push("/groups"))
: setErrorAlert(`Failed to edit group.`); : setErrorAlert(`Failed to edit group.`);
}) })
.catch(() => setErrorAlert(`Failed to edit group.`)); .catch(() => {
console.log("outer");
setErrorAlert(`Failed to edit group.`);
});
}} }}
> >
Apply Apply

View File

@@ -242,17 +242,17 @@ const ServerDashboard = (props) => {
onClick={() => onClick={() =>
stopServer(e.name) stopServer(e.name)
.then((res) => { .then((res) => {
data < 300 if (res.status < 300) {
? updateUsers(...slice) updateUsers(...slice)
.then((data) => { .then((data) => {
dispatchPageUpdate(data, page); dispatchPageUpdate(data, page);
}) })
.catch(() => .catch(() =>
setErrorAlert( setErrorAlert(`Failed to update users list.`)
`Failed to update users list.` );
) } else {
) setErrorAlert(`Failed to stop server.`);
: setErrorAlert(`Failed to stop server`); }
return res; return res;
}) })
.catch(() => setErrorAlert(`Failed to stop server.`)) .catch(() => setErrorAlert(`Failed to stop server.`))
@@ -267,17 +267,17 @@ const ServerDashboard = (props) => {
onClick={() => onClick={() =>
startServer(e.name) startServer(e.name)
.then((res) => { .then((res) => {
data < 300 if (res.status < 300) {
? updateUsers(...slice) updateUsers(...slice)
.then((data) => { .then((data) => {
dispatchPageUpdate(data, page); dispatchPageUpdate(data, page);
}) })
.catch(() => .catch(() =>
setErrorAlert( setErrorAlert(`Failed to update users list.`)
`Failed to update users list.` );
) } else {
) setErrorAlert(`Failed to start server.`);
: setErrorAlert(`Failed to start server`); }
return res; return res;
}) })
.catch(() => { .catch(() => {

View File

@@ -33,11 +33,7 @@ var serverDashboardJsx = (spy) => (
); );
var mockAsync = (data) => var mockAsync = (data) =>
jest jest.fn().mockImplementation(() => Promise.resolve(data ? data : { k: "v" }));
.fn()
.mockImplementation(() =>
Promise.resolve({ json: () => Promise.resolve(data ? data : { k: "v" }) })
);
var mockAsyncRejection = () => var mockAsyncRejection = () =>
jest.fn().mockImplementation(() => Promise.reject()); jest.fn().mockImplementation(() => Promise.reject());

File diff suppressed because one or more lines are too long